Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.parseJSON returning null

Tags:

jquery

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

like image 676
Beginner Avatar asked May 28 '12 14:05

Beginner


1 Answers

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.

like image 116
Shyju Avatar answered Sep 24 '22 01:09

Shyju