2013-01-24 72 views
0

我在解析jQuery中的json数组时遇到了问题。json在jQuery中的解析问题

我的JSON数组是

({resultCount:1, results:[{wrapperType:"track", kind:"song", artistId:255303209, collectionId:536282724, trackId:536282832, artistName:"Flo Rida", collectionName:"Wild Ones (Deluxe Version)", trackName:"I Cry", collectionCensoredName:"Wild Ones (Deluxe Version)", trackCensoredName:"I Cry", artistViewUrl:"https://itunes.apple.com/us/artist/flo-rida/id255303209?uo=4", collectionViewUrl:"https://itunes.apple.com/us/album/i-cry/id536282724?i=536282832&uo=4", trackViewUrl:"https://itunes.apple.com/us/album/i-cry/id536282724?i=536282832&uo=4", previewUrl:"http://a1278.phobos.apple.com/us/r1000/073/Music/09/3d/27/mzm.wwzzwbfq.aac.p.m4a", artworkUrl30:"http://a1395.phobos.apple.com/us/r1000/112/Music/v4/25/03/bb/2503bb1c-fbf4-4f5d-b249-9a2c3cfe24d6/075679960399.30x30-50.jpg", artworkUrl60:"http://a1459.phobos.apple.com/us/r1000/112/Music/v4/25/03/bb/2503bb1c-fbf4-4f5d-b249-9a2c3cfe24d6/075679960399.60x60-50.jpg", artworkUrl100:"http://a1796.phobos.apple.com/us/r1000/112/Music/v4/25/03/bb/2503bb1c-fbf4-4f5d-b249-9a2c3cfe24d6/075679960399.100x100-75.jpg", collectionPrice:7.99, trackPrice:1.29, releaseDate:"2012-06-22T07:00:00Z", collectionExplicitness:"notExplicit", trackExplicitness:"notExplicit", discCount:1, discNumber:1, trackCount:10, trackNumber:8, trackTimeMillis:223800, country:"USA", currency:"USD", primaryGenreName:"Hip Hop/Rap"}]}) 

在这阵我得artworkUrl30,TRACKNAME。 如何做到这一点? 当我尝试解析这个我得到这个错误 语法错误:JSON.parse:预计双引号的属性名

编辑 我打电话这是iTunes的回调像

function GetDetailsFromitunes(data){ 

    var mvar = jQuery.parseJSON(data); 
    console.log(mvar.resultCount); 

    } 

我根据我的工作本文件提前

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html#searching

谢谢。

+1

你能告诉我们你用来检索这个代码以及你如何试图解析它吗? –

+0

@ExplosionPills回复它的一个itune回调函数的任何帮助? –

+0

你什么时候调用'GetDetailsFromitunes'? –

回答

1
$(document).ready(function() { 
    var url = "http://itunes.apple.com/lookup?id=536282832"; 
    $.getJSON(url + "&callback=?", null, function(data) { 
     console.log(data.results[0].artworkUrl30, data.results[0].trackName); 
    }); 
}); 
+0

谢谢... 其作品 –

3

错误消息不能更清晰。你必须引用您的属性名称:

{ "resultCount":1, "results": [{"wrapperType":"track"}, {"Keep": "going"}] } 

你有现在,而被有效的JavaScript,is invalid JSON的方式。

+0

感谢您的快速回复,但我从itunes得到这个返回数组实际上,当我在浏览器中显示url时显示”“,但是当使用它与回调函数时,我得到了这个问题,我试着用jQuery.parseJSON是不是正确? –