- 1.开始我也考虑过用parse和eval去直接转换为数组集合,但是里面的number超过16位精度会丢失
- 2.后面想到先把number数字正则筛选为string形式,然后再去parse转换,这样就能保证精准度一样
const res = "[{\"id\": 1661309874902732803, \"name\": \"上衣\", \"unit\": \"件\", \"price\": 10, \"quantity\": 1}, {\"id\": 1661310354269736962, \"name\": \"头饰\", \"unit\": \"套\", \"price\": 15, \"quantity\": 2}]"
const convertedJsonString = res.replace(/"id": (\d+)/g, '"id": "$1"')
const resArray = JSON.parse(convertedJsonString)