这到底有什么区别?
这很好用:
var obj1 = jQuery.parseJSON('{"orderedList": "true"}');
document.write("obj1 "+ obj1.orderedList );
但以下不起作用:
var obj2 = jQuery.parseJSON("{'orderedList': 'true'}");
document.write("obj2 "+ obj2.orderedList );
这是为什么呢?
最佳答案
这是因为双引号被认为是标准的,而单引号不是。这并不是 JQuery 所特有的,而是关于 JSON standard .因此,无论 JS 工具包如何,您都应该期待相同的行为。
A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.
更新
或者它可能是 jQuery single quote in JSON response 的副本
关于javascript - jQuery.parseJSON 单引号与双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355655/