Javascript - convert an EXTRA LARGE Number to string in JSON before the default parsing

前端 未结 4 1077
走了就别回头了
走了就别回头了 2021-01-20 00:31

As I mentioned in THIS QUESTION, I have problem when getting the response from the server.

I receive an array of objects with these attributes:

[{
\"         


        
4条回答
  •  清酒与你
    2021-01-20 00:54

    Assuming that you receive the data as a Json string with the numbers inside them, there is no way to preserve the data using JSON.parse. Even if you use the second argument to add a transformation function, it will only be run after the default parsing has parsed the numbers with a loss of information in case of large numbers. You need to manipulate the string directly to wrap the number in quotes using e.g. a regular expression.

    You can also use the json-bigint npm package: https://www.npmjs.com/package/json-bigint

提交回复
热议问题