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规范中找到关于这方面的内容.尽管他们在示例中使用了引号.

推荐答案

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相关问答推荐

将嵌套的json中的字符串强制转换为数字

Jolt将键和值转换为单独的数组集

通过在织女星简化图上裁剪来显示文本

在Ruby的json中压缩单个字段

交换键和数组值,将旧键转换为新数组值,使用 jq

将 std::可选值存储到 json 文件 C++

在 PowerShell 中通过 aws cli 创建 cloudwatch alert 时出现字符串解析错误

如何使用Powershell查找所有包含特定键值对的JSON对象并迭代所有对象?

如何在 jq 中按 IP 地址排序?

使用 System.Text.Json 序列化记录成员

如何在 Django 的模板语言中获取 json 键和值?

单元测试球衣 Restful Services

Angularjs访问本地json文件

如何从 JSON 对象中获取日期

没有很多类的 GSON 解析

如何使用 jq 将 JSON 对象流转换为数组

如何在 json 编码字符串内的子数组数据周围添加方括号?

在浏览器中查看 JSON 文件

js 中奇怪的 JSON 解析行为,Unexpected token :

ASP.NET Web API JSON 输出中没有时间的日期