Suppose you have response somewhat like this:
var response = '{"result":true,"total-count":1}';
var getValues = JSON.parse(response);
document.write(getValues.result + ", " + getValues.total-count;
You can simple use JSON.parse() method to get the values of your response and then use it accordingly. Most of the browsers support JSON.parse().
Also you need to make to sure that your JSON code is valid.
You can also use eval function for this purpose. But it is not recommended if you are getting the JSON object from another source that isn't absolutely trusted.
Here is an example of using eval:-
var response = '{"result":true,"total-count":1}';
var getValues = eval("(function(){return " + response + ";})()");
alert(getValues.result);
alert(getValues.total-count);
0 Comment(s)