首页 > json遍历

json遍历

js有点不熟,弄了半天还弄不好!求大神们

JsonCallBack({"retcode":"0","uin":"0","total":"10","start":"-1","songs":[{"id": "0","data": "http://xxx.xxx.cn/zorro.mp3|用户|http://xxx.xxx.cn/zorro.gif|类别|http://xxx.xxx.cn/zorro.gif|标题http://xxx.xxx.cn/zorro.gif|271|1|0|0|10791177|0|320000|0|29298365|30294145|6185642","url": "http://xxx.xxx.cn/zorro.mp3"}]})

要输出

{url:"http://xxx.xxx.cn/zorro.mp3",pic:"http://xxx.xxx.cn/zorro.gif",cat:"类别",title:"标题"}

这是jsonp吧,在回调函数里头直接按照对象的格式读取就好了。

function(response) {
    var infomation = response.songs.data.split('|');
    result = {
        url: response.songs.url,
        pic: infomation[2],
        cat: infomation[3],
        title: infomation[5].replace(infomation[2], '')
    }
}

result就是你想要的结果了。


$.ajax({
                type:'GET',
                dataType:'jsonp',
                jsonp:'jsonp',
                                jsonCallback:'jsonp',
                url:'http://fm.izda.com/index.php?a=guessyoulike',
                success:function(response) {
                                var infomation = response.songs.data.split('|');
                                result = {
                                    url: response.songs.url,
                                    pic: infomation[2],
                                    cat: infomation[3],
                                    title: infomation[5].replace(infomation[2], '')
                                          }
                                $("body").append(result);
                },
                error:function() {
                    alert("Sorry, I can't get it"); 
                }
            });
【热门文章】
【热门文章】