【问题标题】:Parse json from Yahoo pipes using jquery/ javascript使用 jquery/javascript 从 Yahoo 管道解析 json
【发布时间】:2011-12-08 08:13:24
【问题描述】:

这是我从 Yahoo 管道获取的 json 格式。

 {"count":3,
        "value":{
            "title":"Freak count feed",
            "description":"Pipes Output",
            "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=565sdf6as5d4fasdac94835f",
            "pubDate":"Sat, 15 Jan 2011 05:53:12 -0320",
            "generator":"http:\/\/pipes.yahoo.com\/pipes\/","callback":"",
            "items":[
                {"title":"photos count",
                "y:title":"photos count",
                "description":"6"},
                {"title":"videos count",
                "y:title":"videos count",
                "description":"null"},
                {"title":"blogs count",
                "y:title":"blogs count",
                "description":"7"}
                ]
                            }
        }

我有雅虎管道网址。如何使用 jquery 从 url 中解析 json 以从每个内容类型的“描述”中获取计数?

【问题讨论】:

    标签: javascript jquery json parsing


    【解决方案1】:

    试试-

    var data = json string
    
    $(data.value.items).each(function(index, element){
        alert(element.title+' : '+element.description);
    })
    

    演示 - http://jsfiddle.net/T6ra3/

    【讨论】:

      【解决方案2】:

      如果您使用 jquery 处理 ajax 请求,您可以执行以下操作,并且所有内容都已被安全解析和评估。

      $.get(url, arguments, function(data){...},"json");
      

      将 json 添加到 $.get $.post 或 $.ajax 调用的末尾将自动为您解析 json。如果您愿意,这也适用于“xml”。

      之后,您只需像这样访问它:

      $.post(url, {arg1:"arg1", arg2:"arg2"},
         function(data){
            alert(data.value.items[0].title);
            alert(data.value.items[0].description);
         }, "json");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-15
        • 2012-06-22
        相关资源
        最近更新 更多