How to parse JSON in JavaScript

by THavamani 2013-08-12 10:27:01

Here is an Example:

var response = '{"subj":true,"mark":1}';

This JSON variable contain two values with variables name 'subj' and 'mark'
How can I get the values 'subj' and 'mark' from this?

We can parse the JSON by JSON.parse();
Solution:
var json = '{"subj":true,"mark":1}',
obj = JSON.parse(json);

alert(obj.count);

if you are using jQuery use it
var json = '{"subj":true,"mark":1}',
obj = JSON && JSON.parse(json) || $.parseJSON(json);
1056
like
0
dislike
0
mail
flag

You must LOGIN to add comments