0

There is a JSON string in a JSON object

{
 "abc": "{\n  \"_count\": 10,\n  \"_start\": 0,\n  \"_total\": 60\n }",
"success": true
}

I want to get the the the value of abc as JSON object in javascript.

2
  • 1
    please give us some details about the programming language you use... do you use jquery's getJSON function? Commented May 31, 2012 at 13:35
  • I want to capture it in javaascript Commented May 31, 2012 at 15:30

3 Answers 3

3

You would use something like this:

var obj = JSON.parse(JSON.parse(the_string).abc);

NOTE: Your JSON is invalid. Please correct it. It should be somewhat like the below:

{
 "abc": "{\n  \"_count\": 10,\n  \"_start\": 0,\n  \"_total\": 60\n}",
"success": true
}
Sign up to request clarification or add additional context in comments.

Comments

1

If your object is in a variable called obj then obj.abc will return the string value. As this is a JSON string encoding a JavaScript object you need to use JSON.parse to convert it : var abc = JSON.parse (obj.abc);. You now have access to the field vaues abc._count, abc._start and abc._total.

Comments

0

You can do something like this

var json = '{"abc": {"_count": 10,"_start": 0, "_total": 60 },"success": true}';
var obj = JSON.parse(json);
console.log(obj.success);
console.log(obj.abc['_count']);

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.