我如何使用Javascript解析JSON

时间:2018-01-16 23:04:25

标签: javascript json parsing

我在解析json响应时遇到了一些问题。 问题是从以下响应中提取成功消息:

{
  "success": true,
  "reports": [
    { "uid": 10, "report_count": 10, "levels":1, "max_download_capacity": 10 },
    { "uid": 11, "report_count":20, "levels": 2, "max_download_capacity": 30 }
  ]
}

1 个答案:

答案 0 :(得分:2)

使用JSON.parse(JSONString).success,其中JSONString是要解析的JSON响应:



var s ='{"success":true,"reports":[{"uid":10,"report_count":10,"levels":1,"max_download_capacity":10},{"uid":11,"report_count":20,"levels":2,"max_download_capacity":30}]}'

console.log(JSON.parse(s).success);




请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse