Search code examples
javascriptjsonweather-api

JSON - There are no child objects


I am trying to retrieve some specific data, using jQuery to retrieve a JSON Feed.

This is what I am currently doing:

var url  = 'https://api.wunderground.com/api/myapicode/conditions/forecast/q/Tokyo.json?callback=?';

$.getJSON(url, function(d){
    var data = d['current_observation'];
    console.dir(data['display_location']);
});

This successfully returns to the console:

city ==> "Tokyo"
country ==> "JP"
country_iso3166 ==> "JP"
elevation  ==> "8.00000000"
full ==> "Tokyo, Japan"
latitude ==> "35.54999924"
etc...

However, let's say I want to get just the "full" name. If I try:

  console.dir(data['display_location']['full']);

I end up getting the result: There are no child objects

Any ideas on what I am doing wrong here?


Solution

  • console.dir displays the properties (child objects) of the object you pass it.
    It doesn't make sense to call it with a string.

    You should call console.log instead.