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 }
 ]
}
geekonaut
5,9542 gold badges32 silver badges31 bronze badges
asked Jan 16, 2018 at 23:04
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

answered Jan 16, 2018 at 23:06
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.