java JSON解析器可以配置为允许空值吗?

时间:2013-07-15 21:12:18

标签: java json gson

以下json字符串未被解析,因为“orgId”:,不指定空值。有没有办法让json解析器接受这个或者这总是无效的?

200(OK)     Content-Type:application / json

{
    "orgId": ,
    "orgName": "Department of JSON",
    "orgProfile": {
    "publicName": "",
    "numHits": 29,
},
    "orgDescript": {
      "someOrgDescription": ""
    }
}

1 个答案:

答案 0 :(得分:2)

这是语法上无效的JSON。没办法解决它。如果要省略值,有两个选项:

{
    "orgId": null,
    "orgName": "Department of JSON",
    "orgProfile": {
        "publicName": "",
        "numHits": 29
    }
}

{
    "orgName": "Department of JSON",
    "orgProfile": {
        "publicName": "",
        "numHits": 29
    }
}

请参阅http://www.json.org和/或run your JSON through a validator.