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
Add a ment  | 

2 Answers 2

Reset to default 8

The 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