JSON.stringify()和JavaScript对象 [英] JSON.stringify() and JavaScript Objects
本文介绍了JSON.stringify()和JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想,也许我错过了什么在JavaScript中的我只是拿起了。
我想这code在Chrome的控制台:
A = [];
a.name =测试;
JSON.stringify(一);
//返回值[]
A =新的对象();
a.name =测试;
JSON.stringify(一);
//返回值{名:测试}
有什么区别? 我认为新的对象()是Microsoft JScript中的事情吗?我在想什么? 必须错过了一些东西在一个规范的地方。谢谢。
解决方案
A =新的对象()
和
A = []
是不等价的。但是,
A = {}
和
A =新的对象()
是
I'm thinking maybe I missed something in JavaScript that I'm just picking up now.
I tried this code in Chrome console:
a = [];
a.name = "test";
JSON.stringify(a);
// which returns value []
a = new Object();
a.name = "test";
JSON.stringify(a);
// which returns value {"name":"test"}
What is the difference? I thought new Object() was a Microsoft JScript thing? What am I missing? Must have missed something in a spec somewhere. Thanks.
解决方案
a = new Object()
and
a = []
are not equivalent. But,
a = {}
and
a = new Object()
are.
这篇关于JSON.stringify()和JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文