JSON 键是否必须用引号括起来? [英] Do the JSON keys have to be surrounded by quotes?
本文介绍了JSON 键是否必须用引号括起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:以下代码是否适用于 JSON 规范?
Example: Is the following code valid against the JSON Spec?
{
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.
推荐答案
是的,您需要引号.这是为了使它更简单,并避免必须为 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屋!
查看全文