通过 JavaScript 在 JSON 中进行 NaN 和 Infinity 序列化的常识很简单:
JSON.stringify({ x: NaN });
"{"x":null}"
JSON.stringify({ x: Infinity });
"{"x":null}"
问题是这个奇怪的决定背后是什么?
最佳答案
每RFC 7159 - The JavaScript Object Notation (JSON) Data Interchange Format
Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
我推测这是因为 NaN
和 Infinity
实际上并不表示数字和/或不能用任何类型的数字格式表示。
关于javascript - JSON 中 NaN 和 Infinity 的序列化。为什么不支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57127297/