I have this JSon string received from an AJAX call:
{status:OK,addresses:[0,1,2,3,4,5]}
To convert it to a JSon object I have this line:
var jsonObj = eval(jsonString);
But an exception is thrown! This one has no message in the exception variable.
I also tried using
{"status":"OK","addresses":[0,1,2,3,4,5]}
And, yet again, an exception is thrown but saying that an unexpected character ‘&’ was found.
I’m using Struts2 and the JSon is received from an action.
Any help will be appreciated.
Thank you
is not valid JSON because the quotes around
statusandaddressesare missing, and is neither valid JSON nor valid JavaScript since the quotes aroundOKare missing.Also, don’t use
evalto parse JSON – it allows an attacker to execute arbitrary JavaScript in the context of your page. Instead, use the safe alternativesJSON.parse(built-in in modern browsers and other EcmaScript 5 implementations) or JSON2.