Parse JSON with large numbers javascript

2019-02-19 10:48发布

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条回答
登录 后发表回答