【问题标题】:parsing json by jquery's getJSON for twitter api search results not working通过 jquery 的 getJSON 解析 json 以获取 twitter api 搜索结果不起作用
【发布时间】:2011-10-30 22:58:14
【问题描述】:

问题:对于给定的查询,我尝试从 twitter api 结果中解析 json。

代码在:http://jsfiddle.net/Nstnx/176/

【问题讨论】:

  • 为什么要对 url 做两次请求?

标签: jquery search twitter getjson


【解决方案1】:

试试这个

var url = "http://search.twitter.com/search.json?callback=?&rpp=50&q='ramlila'";
    $.getJSON(url, function(data) {
  var items = [];      

        var twitterList = $( "<ul />" );
        $.each( data.results, function( index, item ) {
           alert(data.results[index].text);
            $( "<li />", { "text" : item.from_user} )
                .appendTo( twitterList );
        });
        $( "#output" ).fadeOut( "fast", function(){
            $( this ).empty()
                .append( twitterList )
                .fadeIn( "slow" );            
        });


});

http://jsfiddle.net/Nstnx/182/

【讨论】:

    【解决方案2】:

    我在这方面落后了,cwallenpoole 应该得到任何功劳,因为 更快,但这是一个有效的演示 -

    http://jsfiddle.net/nkQ4Q/

    【讨论】:

      【解决方案3】:

      data 参数具有results 属性。您想对其进行迭代,而不是直接对数据进行迭代:

      这个

      $.each( data, function( index, item ) {
      

      应该是

      $.each( data.results, function( index, item ) {
      

      【讨论】:

        猜你喜欢
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 2011-08-24
        • 2013-04-28
        • 1970-01-01
        • 1970-01-01
        • 2013-01-19
        • 1970-01-01
        相关资源
        最近更新 更多