How to parse a JSON data (type : BigInt) in TypeScript

落爺英雄遲暮 提交于 2020-12-11 10:19:50

问题


I have a simple request but It seems to be harder than expected. I have to parse a bigint from a JSON stream. The value is 990000000069396215. In my code, this value is declared in TypeScript like this: id_address: bigint. But this is not working, the value is truncated, and return nothing like 9900000000693962100

How can I simply manage this bigint in my code?


回答1:


I guess you need to do something like this,

export interface Address {
id_address: string;
}

Then somewhere in your code where you implement this interface you need to do,

const value = BigInt(id_address);  // I am guessing that inside your class you have spread your props and you can access id_address. So inside value you will get your Big integer value.

Reference for BigInt.



来源:https://stackoverflow.com/questions/62539236/how-to-parse-a-json-data-type-bigint-in-typescript

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