JavaScript parse function JSON.parse does not work as expected -


the case:

var s = '{"a": 2}'; var d = json.parse(s); // d = object {a: 2} 

it ok.

the similar case not parse string, however. why?

var s = "{'a': 2}";  var d= json.parse(s) // uncaught syntaxerror: unexpected token ' in json @ position 1 

expected result - parsed object in first case. should have worked because ' , " interchangeable in javascript.

according standard, need double quotes denotes string, key is.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -