当前位置:网站首页>The solution of page accepting more than 18 digits

The solution of page accepting more than 18 digits

2020-12-07 09:03:53 yiyou12138

Practical problems

let result = {
  "acookieId": null,
  "adjustFee": "0.00",
  "alipayId": null,
  "alipayNo": 2020120422001188551422599081,
  "alipayPoint": "0",
  "alipayUrl": "2020120422001188551422599081-url",
  "alipayWarnMsg": null,
  "allowAppkeys": null
}
It's a piece of my work that I came back to json data , because alipayNo Field value exceeds 18 Digit number , This leads to the data being processed JSON.stringify() The following numbers will be displayed on the page and will become 0.

I solved it in the following way

let matchArray = result.match(/"[a-zA-Z]*":d{18}d+/g)
//  Because this number is in alipayUrl It will also appear in the string , So you need to match the whole field first 
let matchArrayItem = matchArray.replace(/d{18}d+/g, '"$&"')
//  Add double quotation marks to the field value found above , Convert to string 
result = result.replace(matchArray, matchArrayItem)
//  Just replace the original value 

版权声明
本文为[yiyou12138]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012070903290736.html