i want to parse json to string in javascript. the response something like
var response = '{"result":true,"count":1}';
how i can get the result value and count from this json
i want to parse json to string in javascript. the response something like
how i can get the result value and count from this json | |||||||||||||||
feedback
|
Most browsers support
For the browsers that don't you can implement it using json2.js. As noted in the comments, if you're already using jQuery, there is a
This will ensure you use native | |||||||||||||||
feedback
|
Without using a library you can use eg...
| |||||
feedback
|
First of all, you have to make sure that the JSON code is valid. After that, I would recommend using a JavaScript library such as jQuery or Prototype if you can because these things are handled well in those libraries. On the other hand, if you don't want to use a library and you can vouch for the validity of the JSON object, I would simply wrap string in an anonymous function and use the eval function. This is not recommended if you are getting the JSON object from another source that isn't absolutely trusted because the eval function allows for renegade code if you will. Here is an example of using the eval function:
If you control what browser is being used or you are not worried people with older browser, you can always use the JSON.parse method. This is really the ideal solution for the future. | ||||
feedback
|