javascript - JSON 数字是否与 JavaScript 的数字相关联?

标签 javascript java json

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 or 3.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/

相关文章:

java - Spring Java 配置 : Specify class only

java - Netbeans 编辑器如何知道文件在撤消后未被修改?

javascript - 通过按钮生成表格

javascript - 我如何以编程方式在 native react 中发送短信?

javascript - 在 fabric js 中绘制外部边界框

javascript - 在 Javascript 中对嵌套数组进行分组

java - 从 Java 打开命令提示符

javascript - ng-repeat(迭代)Angular 中的复杂 json 对象

javascript - 得到“未定义ReferenceError”

Javascript JSON 未知行为