I want to parse a JSON string in JavaScript. The response is something like
var response = '{"result":true,"count":1}';
How can I get the values result
and count
from this?
I want to parse a JSON string in JavaScript. The response is something like
var response = '{"result":true,"count":1}';
How can I get the values result
and count
from this?
The easiest way using
parse()
method:this is an example of how to get values:
Without using a library you can use
eval
- the only time you should use. It's safer to use a library though.eg...
If you are getting this from an outside site it might be helpful to use jQuery's getJSON. If it's a list you can iterate through it with $.each
If you want to use JSON 3 for older browsers, you can load it conditionally with:
Now the standard
window.JSON
object is available to you no matter what browser a client is running.