I am facing some problem in parsing a json response. The problem is to extract the success message from the response below:
{
"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 }
]
}
geekonaut
5,9542 gold badges32 silver badges31 bronze badges
1 Answer 1
Use JSON.parse(JSONString).success, where JSONString is the JSON response to be parsed:
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);
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
answered Jan 16, 2018 at 23:06
Rick Hitchcock
35.7k5 gold badges51 silver badges83 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
response.successwill do it assuming your response is coming viaresponsevar/parameter