Jquery GetJson - 如何阅读回复?

发布于 2024-10-20 00:45:30 字数 1238 浏览 5 评论 0原文


我总是遇到同样的问题,我很难阅读 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 ....

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

你怎么读这个?有什么好的想法吗?

提前致谢!
彼得

i have always the same problem, it is hard for me to read the reply from a json post.

For example

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

   });

});

The Reply

{"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 ....

Sometimes i need an hour to get it -.- ...

How do you read this? Any nice ideas?

Thanks in advance!
Peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-10-27 00:45:31

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

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

   });

});

When I ran the code you pasted in my Firebug console without the feed I saw this object model:

enter image description here

So as you can see feed is not a child of item, and that's why you were getting an error.

Try this instead

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

   });

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文