JSON规范 - 键必须用引号括起来吗? [英] JSON Spec - does the key have to be surrounded with quotes?
本文介绍了JSON规范 - 键必须用引号括起来吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
以下代码针对 JSON规范有效吗?
{
precision: "zip"
}
或者我应该总是使用下面的语法? (如果是,为什么?)
Or should I always use the following syntax? (And if so, why?)
{
"precision": "zip"
}
我在JSON规范中没有真正找到这个。虽然他们在他们的例子中使用他们的键引号。 (所以我现在也是这样)
I haven't really found something about this in the JSON specifications. Although they use quotes around their keys in their examples. (So I'll do that too for now)
推荐答案
是的,你需要引号。这是为了更简单,避免对javascript保留关键字使用另一种转义方法,即 {for:foo}
。
Yes, you need quotation marks. This is to make it simpler and to avoid having to have another escape method for javascript reserved keywords, ie {for:"foo"}
.
这篇关于JSON规范 - 键必须用引号括起来吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文