I used the PHP built-in function json_encode()
to covert an object array to json string
. Then I use AJAX method to get the xmlhttp.responseText
. I use document.write(xmlhttp.responseText)
to check the response string. For example, the string is as follow:
{"index":0,"marks":2}
But, when I use JSON.parse()
to parse the JSON string, I get a syntax error. So, I copy this string to JSONLint
to check whether it's valid, the result is no.
Parse error on line 1:
{ "index": 0
^
Expecting '{', '['
But when I input it by hand, it's valid. Why?