解析对象时,JSON.stringify()是否总是忽略方法吗? [英] Does JSON.stringify() always ignore methods when parsing objects?

查看:88
本文介绍了解析对象时,JSON.stringify()是否总是忽略方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mozilla文档:

如果在转换过程中遇到未定义的函数或XML值,则将其忽略(在对象中找到)或将其检查为空(在数组中找到).

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).

我的问题是:所有现代浏览器都以这种方式运行吗?我可以依靠stringify()忽略我的对象方法吗?

My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?

推荐答案

可以在规范中找到JSON.stringify的完整算法:

The complete algorithm for JSON.stringify can be found in the specification: http://es5.github.com/#x15.12.3.

基本上,对于不是对象,null,布尔值,数字或字符串的每个值,序列化函数都会返回undefined,并且不会呈现undefined值.

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.

并不一定保证每个浏览器都以这种方式实现它,但是唯一脱离常规的浏览器通常是IE.其他所有浏览器都非常符合规范.

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.

这篇关于解析对象时,JSON.stringify()是否总是忽略方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆