Parse JSON with large numbers javascript

我的梦境 提交于 2019-12-04 01:52:50

问题


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 response:

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/35711076/parse-json-with-large-numbers-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!