Jquery GetJson - 如何阅读回复?

时间:2011-03-04 08:35:54

标签: jquery json reply


我总是遇到同样的问题,我很难阅读json帖子的回复。

例如

$.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 ....

有时我需要一个小时才能得到它 - .- ......

你怎么读这个?有什么好主意吗?

提前致谢!
彼得

1 个答案:

答案 0 :(得分:1)

当我在没有feed的情况下运行你在我的Firebug控制台中粘贴的代码时,我看到了这个对象模型:

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

   });

});
相关问题