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 badges4 Answers
Reset to default 6console.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
评论列表(0条)