I am getting JSON back from a web service. When I use jQuery.parseJSON
, for some reason it is null. This is an example of the JSON (got by using JSON.stringify(msg)
)
{"0":{"i":"1x 8351-3 & 2 x 8352-3","D":"Notes","V":"1x 8351-3 & 2 x 8352-3"},"1":{"i":"PC3","D":"Unit","V":"PC3"},"2":{"i":"PC3","D":"Unit","De":"Unit","V":"PC3"}}
var data = jQuery.parseJSON(msg);
data is null? Am I missing something? Thanks
If your JSON
is like this (assuming you are fetching data from web sevice via getJSON)
{"error":"Error KL005"}
Then you don't need to call the parseJSON
. It is a well formed JSON object. You can simply parse thru it.
var response={"error":"Error KL005"};
alert(response.error);
Example : http://jsfiddle.net/6YHeB/2/
Use JsonLint to check whether your expressions are valid JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With