无法加载嵌套的Json数组

时间:2015-01-21 09:45:53

标签: android arrays json

我的Json值是

{"candidateName":"Check","success":true,"candidateWorkExperience":"[{\"candidateWorkExperienceId\":7486,\"candidateBiographyRef\":{\"primaryKey\":98567,\"percent\":0.0,\"specialization\":0,\"rating\":0,\"description\":\"Check\",\"properties\":{},\"secondaryKey\":0,\"start\":0,\"limit\":0,\"noOfStud\":0,\"typingTest\":false,\"isPostGrad\":false},\"designation\":\"Check\",\"company\":\"Check\",\"startDate\":\"Jan 1, 2012\",\"endDate\":\"Jan 1, 2014\",\"workTypeMasterRef\":{\"primaryKey\":2,\"percent\":0.0,\"specialization\":0,\"rating\":0,\"description\":\"Permanent\",\"properties\":{},\"secondaryKey\":0,\"start\":0,\"limit\":0,\"noOfStud\":0,\"typingTest\":false,\"isPostGrad\":false},\"achivements\":\"Check\",\"candidateRecordStatus\":\"EXISTING\",\"currentCompany\":\"false\"}]"}

我试图通过

传递相同的内容
JSONArray jarray = jsono.getJSONArray("candidateWorkExperience");

但我得到org.json.JSON.typeMismatch例外。

任何人都可以建议如何将json数据加载到数组中。

2 个答案:

答案 0 :(得分:2)

你的问题是你把js正在解释的“[]”解释为字符串而不是数组。

数组由[]括起,没有“。

尝试下一个json,让我知道这是否可以解决您的问题:

{
"candidateName": "Check",
"success": true,
"candidateWorkExperience": [
    {
        "candidateWorkExperienceId": 7486,
        "candidateBiographyRef": {
            "primaryKey": 98567,
            "percent": 0.0,
            "specialization": 0,
            "rating": 0,
            "description": "Check",
            "properties": {

            },
            "secondaryKey": 0,
            "start": 0,
            "limit": 0,
            "noOfStud": 0,
            "typingTest": false,
            "isPostGrad": false
        },
        "designation": "Check",
        "company": "Check",
        "startDate": "Jan1, 2012",
        "endDate": "Jan1, 2014",
        "workTypeMasterRef": {
            "primaryKey": 2,
            "percent": 0.0,
            "specialization": 0,
            "rating": 0,
            "description": "Permanent",
            "properties": {

            },
            "secondaryKey": 0,
            "start": 0,
            "limit": 0,
            "noOfStud": 0,
            "typingTest": false,
            "isPostGrad": false
        },
        "achivements": "Check",
        "candidateRecordStatus": "EXISTING",
        "currentCompany": "false"
    }
]
}

答案 1 :(得分:0)

您的JSON不正确,您的“candidateWorkExperience”参数不是JSONArray而是JSONString。

粘贴您的JSON here

您将看到如何解析JSON。

干杯!