当前位置:  开发笔记 > 编程语言 > 正文

Is an empty string a valid JSON key?

如何解决《IsanemptystringavalidJSONkey?》经验,为你挑选了0个好方法。

Is a JSON object having an empty string as a key valid, for example { "c": "x", "": "y" }?

It certainly seems to be, or at least it doesn't seem to break the web if I using it in a browser as per this jsfiddle having the following code:

var a = { "a": "x", "b": "y" };
var b = { "c": "x", "": "y" };
var c = JSON.stringify(a);
var d = JSON.stringify(b);
console.log(c);
console.log(d);
var e = JSON.parse(c);
var f = JSON.parse(d);
console.log(e);
console.log(f);

There is a good reason why I need (want) to use an empty string for a key, but am I just asking for trouble, in terms of browser compatibility and future-proofing?

推荐阅读
女女的家_747
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有