I would like to call the meters (732) piece of data from the following json API return:
{"results":1,"data":[{"wind":{"degrees":200,"speed_kts":6,"speed_mph":7,"speed_mps":3,"speed_kph":11},"temperature":{"celsius":16,"fahrenheit":61},"dewpoint":{"celsius":14,"fahrenheit":57},"humidity":{"percent":88},"barometer":{"hg":30.06,"hpa":1018,"kpa":101.79,"mb":1017.92},"visibility":{"miles":"Greater than 6","miles_float":6.21,"meters":"10,000+","meters_float":10000},"ceiling":{"code":"BKN","text":"Broken","feet":2400,"meters":732,"base_feet_agl":2400,"base_meters_agl":732},"elevation":{"feet":256,"meters":78},"location":{"coordinates":[-2.27495,53.353699],"type":"Point"},"icao":"EGCC","station":{"name":"Manchester Airport"},"observed":"2020-07-18T00:50:00.000Z","raw_text":"EGCC 180050Z AUTO 20006KT 9999 BKN024 16/14 Q1018","flight_category":"MVFR","clouds":[{"code":"BKN","text":"Broken","feet":2400,"meters":732,"base_feet_agl":2400,"base_meters_agl":732}],"conditions":[]}]}
This code doesn’t seem to call it:
jQuery.ajax({
type: 'GET',
url: 'https://api.checkwx.com/metar/EGCC/decoded',
headers: { 'X-API-Key': 'apikey' },
dataType: 'json',
success: function(data) {
console.log(data)
var ceiling = data.ceiling.feet;
jQuery('#a53feet').html( ceiling );
}
});
Html:
<span id="a53feet"></span>
Is it something in the call pathway (data.ceiling.feet), that isn’t right?
2
Answers
The json returned is an array you need to use like below
For accessing feet data
data.data[0].ceiling.feet;
For accessing meters data
data.data[0].ceiling.meters
If you see the console.log, data is an object which has data as an array , so for access the data that you are trying to , you need to do something like below: