JQuery.parseJSON returns null

I get JSON back from a web service. When I use jQuery.parseJSON , for some reason it is zero. This is a JSON example (obtained 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); 

are the data equal to zero? Am I missing something? Thanks

+6
source share
1 answer

If your JSON looks like this (assuming you are retrieving data from a web service via getJSON)

  {"error":"Error KL005"} 

Then you do not need to call parseJSON . This is a well-formed JSON object. You can just take it apart.

 var response={"error":"Error KL005"}; alert(response.error); 

Example: http://jsfiddle.net/6YHeB/2/

Use JsonLint to check if your JSON expressions are valid.

+7
source

Source: https://habr.com/ru/post/916849/


All Articles