开发者

Can't Read Twitter Json

开发者 https://www.devze.com 2023-01-18 07:49 出处:网络
I\'m a total loss. I have this function to read the Twitter Json. The Json is val开发者_高级运维id but the value is coming back as \'undefined\' when I run it.

I'm a total loss. I have this function to read the Twitter Json. The Json is val开发者_高级运维id but the value is coming back as 'undefined' when I run it.

$.getJSON("http://twitter.com/users/show.json?screen_name=starbucks&callback=?" , function(data) {
var testing = (data.length);
alert(testing);
})


data is an object* not an array** so it doesn't have a length property.***

Use a debugger like Firebug, Safari/Chrome dev tools and use this code instead:

$.getJSON("http://twitter.com/users/show.json?screen_name=starbucks&callback=?" ,
    function(data) {
        console.log(data);
    });

and you can see that the data is coming back to you perfectly.

Try this to see what I mean, preferably with a JavaScript console available.


*e.g., something that looks like {key: value, ...}; also known as a hash or an associative array

**e.g., something that looks like: [foo, bar, baz, ...]

*** unless, of course, someone was evil and constructed the object like so:

data = {
    ...
    length: 8675309,
    ...
};
0

精彩评论

暂无评论...
验证码 换一张
取 消