jQuery.parseJSON 单引号与双引号 [英] jQuery.parseJSON single quote vs double quote

查看:30
本文介绍了jQuery.parseJSON 单引号与双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上有什么区别?

这很好用:

var obj1 = jQuery.parseJSON('{"orderedList": "true"}');
document.write("obj1 "+ obj1.orderedList );

但以下不起作用:

var obj2 = jQuery.parseJSON("{'orderedList': 'true'}");
document.write("obj2 "+ obj2.orderedList );

这是为什么?

推荐答案

那是因为双引号被认为是标准的,而单引号不是.这并不是真正特定于 JQuery,而是关于 JSON 标准.因此,无论 JS 工具包如何,您都应该期待相同的行为.

That's because double quotes is considered standard while single quote is not. This is not really specific to JQuery, but its about JSON standard. So irrespective of JS toolkit, you should expect same behaviour.

值可以是双引号中的字符串、数字、真假或空值、对象或数组.这些结构可以嵌套.

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.

更新

或者它可能是 JSON 响应中的 jQuery 单引号

这篇关于jQuery.parseJSON 单引号与双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆