2011-03-04 75 views
0


我总是有同样的问题,我很难从json文章阅读回复。Jquery GetJson - 如何阅读答复?

例如

$.getJSON('http://gdata.youtube.com/feeds/api/users/live/subscriptions?alt=json', function(data) { 

    $.each(data.feed.entry, function(i, item) { 

     console.log(item.feed.link.i); // did not work 

    }); 

}); 

的批复

{"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$yt":"http://gdata.youtube.com/schemas/2007","id":{"$t":"http://gdata.youtube.com/feeds/api/users/live/subscriptions"},"updated":{"$t":"2011-03-04T08:31:20.148Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#subscription"}],"title":{"$t":"Subscriptions of live","type":"text"},"logo":{"$t":"http://www.youtube.com/img/pic_youtubelogo_123x63.gif"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/users/live"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/profil .... 

有时候,我需要一个小时就搞定它-.- ...

你怎么看这一点?任何好主意?

在此先感谢!
彼得

+0

你得到什么样的错误信息?它是“未定义”吗? – picardo 2011-03-04 08:47:41

+0

对,我弄不明白。 – Peter 2011-03-04 08:54:00

回答

1

当我跑我看到这个对象模型,你在我的Firebug的控制台没有feed粘贴代码:

enter image description here

因此,大家可以看到feed不是item一个孩子,这就是为什么你得到一个错误。

试试这个

$.getJSON('http://gdata.youtube.com/feeds/api/users/live/subscriptions?alt=json', function(data) { 

    $.each(data.feed.entry, function(i, item) { 

     console.log(item.gd$feedLink); // did not work 

    }); 

});