JSON.parse () doesn't work

By TonyCox on May 11, 2021

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?


Sign in to comment.
Tuongtaccongdong   -  Sep 30, 2021

I don't see anely error :3

mrpaul   -  Sep 07, 2021

I don't see any error

muabanchinhchu   -  Jul 20, 2021

Tôi từng bị, sao khi reset máy thì không bị nửa 🤣

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.