开发者

Parse json from Yahoo pipes using jquery/ javascript

开发者 https://www.devze.com 2023-04-13 10:04 出处:网络
This is the format of the json that I get from Yahoo pipes. {\"count\":3, \"value\":{ \"title\":\"Freak count feed\",

This is the format of the json that I get from Yahoo pipes.

 {"count":3,
        "value":{
            "title":"Freak count feed",
            "description":"Pipes Output",
            "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=565s开发者_StackOverflow社区df6as5d4fasdac94835f",
            "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"}
                ]
                            }
        }

I have the Yahoo pipes url. How do i parse the json from the url using jquery to get the count from the 'description' for each content type?


Try -

var data = json string

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

Demo - http://jsfiddle.net/T6ra3/


If you are using jquery for handling the ajax request you can do the following and everything will be already be safely parsed and evaluated.

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

Adding json to the end of a $.get $.post or $.ajax call will automatically parse the json for you. This also works with "xml" if you want to.

Afterwards you just access it like:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号