[英]Parse JSON with large numbers javascript
I'm getting a JSON
object that includes a long
type value from an API response.我从 API 响应中获取一个包含
long
类型值的JSON
对象。 Since javascript can't handle 64bit numbers, when executing JSON.parse
on the response it rounds the number to the maximum value javascript can handle.由于 javascript 无法处理 64 位数字,因此在响应上执行
JSON.parse
时,它会将数字四舍五入为 javascript 可以处理的最大值。
API response: API响应:
{
"subject": "subjectTitle",
"longNumberKey": 7356270823847851521,
}
When parsing this object to JSON
, longNumberKey
value would be 7356270823847852000
instead of 7356270823847851521
.将此对象解析为
JSON
, longNumberKey
值将是7356270823847852000
而不是7356270823847851521
。 A solution would be to represent this value as a string
but I can't control the API response for that.一种解决方案是将此值表示为
string
但我无法为此控制 API 响应。
-----> json-bignum https://www.npmjs.com/package/json-bignum <------ JSON parser ! -----> json-bignum https://www.npmjs.com/package/json-bignum <------ JSON 解析器!
GMP (GNU multiple precision) with javascript https://github.com/jtobey/javascript-bignum/blob/master/src/gmp-example.html GMP(GNU 多精度)与 javascript https://github.com/jtobey/javascript-bignum/blob/master/src/gmp-example.html
gmp.js https://github.com/kripken/gmp.js?MobileOptOut=1 gmp.js https://github.com/kripken/gmp.js?MobileOptOut=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.