【问题标题】:Jquery getJSON - Get itemsJquery getJSON - 获取项目
【发布时间】:2010-08-23 20:15:23
【问题描述】:

如何从这个 getJSON 中获取作者姓名

http://gdata.youtube.com/feeds/api/videos/tPYtsDPXtOY/comments?alt=json-in-script&callback=jsonp1282584741426&max-results=10

$.getJSON('http://gdata.youtube.com/feeds/api/videos/tPYtsDPXtOY/comments?alt=json-in-script&callback=jsonp1282584741426&max-results=10', function(data) {

 $.each(data.feed.entry, function(i, item) {                
    var title = item['content']['$t']; // work
    var author = item['author']['$t']; // dont work         
    $('body').append('['+author+'] <br /> '+title+'<hr/>');
  });

});

提前致谢! 彼得

【问题讨论】:

    标签: jquery


    【解决方案1】:

    查看响应JSON后,似乎可以更改

    var author = item['author']['$t']; // dont work
    

    var author = item['author'][0]['name']['$t'];
    

    我不确定您是否可以拥有多个作者。

    【讨论】:

    • 请注意:这将是 Firebug 的一个很好的用途。您可以在循环中编写 console.log(item) 以获取每个项目的属性的细分。然后,您可以深入研究并找到答案。 getfirebug.com 以防你不使用它。
    猜你喜欢
    • 1970-01-01
    • 2021-08-06
    • 2012-01-18
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 2023-03-22
    • 2014-07-12
    相关资源
    最近更新 更多