I have an async function below that connects to a weather API and I am trying to extract two data points: Temperature in Fahrenheit & Celsius. The API_Key has been removed, but it can be obtained for free on the site if needed.
Although my console.log(response) statement confirms that I am receiving the json object, I am unsure of how to access these specific data points within the heavily nested json structure.
For example, when attempting to access 'full' for the full city name by using response.observation_location.full, it does not yield the desired result...
Any assistance would be greatly appreciated.
async loadWeather() {
// let zip = this.args.zip || 97239;
let response = await fetch(`http://api.wunderground.com/api/API_KEY/conditions/q/CA/San_Francisco.json`);
console.log(response);
this.weather = await response.json();
// setTimeout( () => { this.loadWeather(); }, 2000);
}
Below is a snippet from the response json:
{
"response": {
"version": "0.1",
"termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
},
"current_observation": {
"image": {
"url": "http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title": "Weather Underground",
"link": "http://www.wunderground.com"
},
"display_location": {
"full": "San Francisco, CA",
"city": "San Francisco",
"state": "CA",
"state_name": "California",
"country": "US",
"country_iso3166": "US",
"zip": "94102",
"magic": "1",
"wmo": "99999",
"latitude": "37.77999878",
"longitude": "-122.41999817",
"elevation": "60.0"
},
"observation_location": {
"full": "SOMA, San Francisco, California",
"city": "SOMA, San Francisco",
"state": "California",
"country": "US",
"country_iso3166": "US",
"latitude": "37.778488",
"longitude": "-122.408005",
"elevation": "23 ft"
},
I have attempted
console.log(response["current_observation"])
to access a nested data value, however, it returns undefined.