So I tested two ways of declaring a json string:
1:
json = "{'name': 'ajsie'}";
obj = JSON.parse(json); // SyntaxError: Unexpected token ILLEGAL
2:
json = '{"name": "ajsie"}';
obj = JSON.parse(json); // Worked!
What is the problem with the first one?
Single quotes are not a valid quote character for strings. From http://www.json.org/: "A value can be a string in double quotes..."
json.org defines a string to use " instead of '. That's my guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With