javascript - JSON - There are no child objects - Stack Overflow

I am trying to retrieve some specific data, using jQuery to retrieve a JSON Feed.This is what I am cu

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

This is what I am currently doing:

var url  = '.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?

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./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?

Share Improve this question asked Aug 27, 2012 at 18:15 DodinasDodinas 6,80522 gold badges78 silver badges109 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

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.

in order to use console.dir(arg) arg should be an object. You are accessing a full key of an object in console.dir(data['display_location']['full']); which is a plain string. use console.log(data['display_location']['full']) instead

You should be using console.log() to get a value instead of an object's properties.

console.dir will show object trees - the properties of the object you pass in. Yet, the property you log is just a string and has no child objects. Use console.log instead.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744684066a4587805.html

相关推荐

  • javascript - JSON - There are no child objects - Stack Overflow

    I am trying to retrieve some specific data, using jQuery to retrieve a JSON Feed.This is what I am cu

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信