Do the JSON keys have to be surrounded by quotes?(转载)
问
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" }
I haven't really found something about this in the JSON specifications. Although they use quotes around their keys in their examples.
答
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"}.
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步