我该如何解析JSON?

时间:2011-11-03 09:50:17

标签: jquery json parsing

  

可能重复:
  Parse JSON with jQuery

我试图解析以下JSON文件。我需要从JSON文件中获取拇指ID,但我不知道如何操作。如何使用jQuery或JavaScript解析以下JSON?

[

{
    "Page": {
        "number": "0",
        "thumb": "http:\/\/cdn.data.com\/files\/aT00NTA0NCZwPTAmdmVyc2lvbj0xJmNtZD12JnNpZz0wNmRiZDQxM2I5MTdhYzZjNzJkYThhYWMyNGZlMmY0Zg%253D%253D\/-w-320.jpg"
    }
}, {
    "Page": {
        "number": "1",
        "thumb": "http:\/\/cdn.data.com\/files\/aT00NTA0NCZwPTEmdmVyc2lvbj0xJmNtZD12JnNpZz05YWI4ODVmNzZhYmQ0NWYxZmRhMmYwZmJkN2U4OTllMA%253D%253D\/-w-320.jpg"
    }
}, {
    "Page": {
        "number": "2",
        "thumb": "http:\/\/cdn.data.com\/files\/aT00NTA0NCZwPTImdmVyc2lvbj0xJmNtZD12JnNpZz1iNjA5NjJjYjIyZDQ3MjY2NWFlZDZkYzczMTdkNmMzNA%253D%253D\/-w-320.jpg"
    }
}, {
    "Page": {
        "number": "3",
        "thumb": "http:\/\/cdn.data.com\/files\/aT00NTA0NCZwPTMmdmVyc2lvbj0xJmNtZD12JnNpZz01MjY0OGMwN2MwZWJhZDYyODFjZjJhNDgxNGQ2MTIxYg%253D%253D\/-w-320.jpg"
    }
}, {
    "Page": {
        "number": "4",
        "thumb": "http:\/\/cdn.data.com\/files\/aT00NTA0NCZwPTQmdmVyc2lvbj0xJmNtZD12JnNpZz03YTAzNWE5OGVmMDFmYTgxY2Q2OTVlZTc2OGFjNTM1Mw%253D%253D\/-w-320.jpg"
    }
}

]

2 个答案:

答案 0 :(得分:5)

试试这个:

var jsonObj = $.parseJSON(theJsonString);
console.log(jsonObj[0].Page.thumb);

答案 1 :(得分:1)

使用jQuery:

    $.getJSON('ajax/test.json', function(data) {
     $.each(data, function(key, val) {
      //insert your code here
     });
    });