用大量JavaScript解析JSON [英] Parse JSON with large numbers javascript

查看:151
本文介绍了用大量JavaScript解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从API响应中得到一个 JSON 对象,该对象包含 long 类型值。
由于javascript无法处理64位数字,因此在响应上执行 JSON.parse 时,会将数字四舍五入为javascript可以处理的最大值。

I'm getting a JSON object that includes a long type value from an API response. 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.

API响应:

    {
       "subject": "subjectTitle",
       "longNumberKey": 7356270823847851521,
    }

当将此对象解析为 JSON 时, longNumberKey 的值将为 7356270823847852000 代替 7356270823847851521
一种解决方案是将该值表示为 string ,但我无法控制该API的响应。

When parsing this object to JSON, longNumberKey value would be 7356270823847852000 instead of 7356270823847851521. A solution would be to represent this value as a string but I can't control the API response for that.

推荐答案

-----> json-bignum https://www.npmjs.com/package/json-bignum < ------ JSON解析器!

-----> json-bignum https://www.npmjs.com/package/json-bignum <------ JSON parser !

具有javascript https://github.com/jtobey/javascript-bignum/blob/master/src/gmp-example.html

GMP (GNU multiple precision) with javascript https://github.com/jtobey/javascript-bignum/blob/master/src/gmp-example.html

gmp.js https://github.com/kripken/gmp。 js?MobileOptOut = 1

这篇关于用大量JavaScript解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆