I have JSON from my server which -
{"canApprove": true, "hasDisplayed": false}
I can parse JSON like this -
var msg = JSON.parse ('{"canApprove": true, "hasDisplayed": false}');
warning (msg.canApprove); // shows true.
In my ajax response function, I caught the exact same json specified previously as the parameter of the jsonObject method -
// response function
function (jsonObject) {
// here jsonObject contains the same json - {"canApprove": true, "hasDisplayed": false}
// But without the surrounding single quote
// I confirmed this by looking at the server side log.
var msg = JSON.parse (jsonObject); // this gives an error
}
But now I got the following error -
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of JSON data
Can anyone tell me why I am getting this error?