JSON数组解析错误

时间:2018-06-26 13:05:44

标签: arrays json

JSON编辑器在第5行显示错误。但是我的JSON一切还好吗?

我的JSON文件:

{
    "status": "ok",
    "errorMessage": "",
    "result": [
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    ]
}

谢谢。

2 个答案:

答案 0 :(得分:0)

结果数组中缺少大括号。

应如下所示:

{
    "status": "ok",
    "errorMessage": "",
    "result": [{
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    }]
}

jsonlint上验证

答案 1 :(得分:0)

“结果”是一个数组([]),您正在定义属性,就好像它是一个对象({})。

您可能希望使其成为对象:

{
   "status":"ok",
   "errorMessage":"",
   "result":{
      "data_x":[
         {
            "date":"2018-03-09T05:17:08",
            "value":12.00
         }
      ],
      "data_y":[
         {
            "date":"2018-03-09T05:17:08",
            "value":36.50
         }
      ],
      "data_z":[
         {
            "date":"2018-03-09T05:17:08",
            "value":88.50
         }
      ]
   }
}

或者,如果您要保留阵列,可以按照imEnCoded says的方式进行操作:

{
    "status": "ok",
    "errorMessage": "",
    "result": [{
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    }]
}