2

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 }
  ]
}
1
  • response.success will do it assuming your response is coming via response var/parameter Commented Jan 16, 2018 at 23:18

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.