JSON 中的数字大小有限制吗?我说的不是 JavaScript,而是 JSON。
JSON 与 JavaScript 如此相关 - 但仅仅因为数字不符合 JavaScript 的数字 View ,是否会使它成为无效的 JSON?
例如,JSON 可以容纳 Java Long 吗?
最佳答案
来自 RFC 7159 :
This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers [IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision. A JSON number such as
1E400
or3.141592653589793238462643383279
may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available.
Note that when such software is used, numbers that are integers and are in the range
[-(2**53)+1, (2**53)-1]
are interoperable in the sense that implementations will agree exactly on their numeric values.
tl;dr:建议您使用可互操作( double )但不是必需的数字。
关于javascript - JSON 数字是否与 JavaScript 的数字相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35192804/