简体   繁体   English

使用大量 javascript 解析 JSON

[英]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 .将此对象解析为JSONlongNumberKey值将是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 响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM