axios-如何处理大整数 [英] axios - how to deal with big integers

查看:132
本文介绍了axios-如何处理大整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的要求:

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

输出为 {值:156144277082605605255}

但应为 {值:156144277082605605}

在这种情况下如何处理Big Integer?我尝试使用 json-bigint 但是,由于我从axios获取了response.data作为对象,所以没有帮助.

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.

推荐答案

我的同事回答了这个问题:

My colleague answered the question:

我必须将response.data转换为字符串.(您可能想知道-为什么无用的功能-只是为了重新定义默认行为,该行为使用JSON.parse将字符串解析为对象-在这里我们跳过了这一步)

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] });

然后使用json-bigint解析

and then parse with json-bigint

JSONBigInt.parse(res.data);

这篇关于axios-如何处理大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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