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
Post a Comment