likes
comments
collection
share

js json parse bigint 丢失精度的问题

作者站长头像
站长
· 阅读数 40

js json parse bigint 丢失精度的问题

1.获取原始数据2.使用正则替换bigint 为 string3.JSON.parse()

const json = '{"smallNumber": 1, "bigNumber" : 9007199254740999}';
console.log(regexbig(json));
function regexbig(input:string) {
    // const re1 = input.replace(/:s*([0-9]{15,})s*(,?)/g, ': "$1" $2')
 //  console.log(re1); return JSON.parse(input);
}