axios - how to deal with big integers

Deadly 提交于 2021-01-27 18:53:22

问题


Here is my request:

    axios.get(url)
    .then(res => {
        console.log(res.data)
    })

The output is { value: 156144277082605255 }

But should be { value: 156144277082605250 }

How to deal with Big Integers in this case? I tried to use json-bigint But since I am getting response.data from axios as object - it doesn't help.


回答1:


My colleague answered the question:

I had to transform my response.data into string. (you may wonder - why the useless function - just to redefine default behavior, which parses string into object with JSON.parse - in here we skip this step)

axios.get(url, { transformResponse: [data  => data] });

and then parse with json-bigint

JSONBigInt.parse(res.data);


来源:https://stackoverflow.com/questions/43787712/axios-how-to-deal-with-big-integers

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