admin管理员组文章数量:1336293
I found the following in the Mozilla-documentation:
If undefined, a function, or an XML value is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).
My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?
I found the following in the Mozilla-documentation:
If undefined, a function, or an XML value is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).
My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?
Share asked Oct 13, 2012 at 4:42 Konstantin SchubertKonstantin Schubert 3,3562 gold badges35 silver badges47 bronze badges 1-
Firefox offers a propriatary method
.toSource()
for all of its objects. While I'd not use it for anything more than testing and debugging, it can be amazingly useful. – Jeremy J Starcher Commented Oct 13, 2012 at 7:35
2 Answers
Reset to default 8The plete algorithm for JSON.stringify
can be found in the specification: https://es5.github.io/x15.12.html#x15.12.3.
Basically, for every value that is not an object, null
, a boolean, a number or a string, the serialisation function returns undefined
and undefined
values are not rendered.
That does not necessarily guarantee that every browser implements it this way, but the only browser getting out of line is normally IE. Every other browser is very close to the specification.
Yes.
Except for IE7, which doesn't implement it, and IE8, which requires document to be in standards mode, stringify works well across browsers
See: http://caniuse./#search=json
本文标签: javascriptDoes JSONstringify() always ignore methods when parsing objectsStack Overflow
版权声明:本文标题:javascript - Does JSON.stringify() always ignore methods when parsing objects? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742405863a2468807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论