- 1.開(kāi)始我也考慮過(guò)用parse和eval去直接轉(zhuǎn)換為數(shù)組集合,但是里面的number超過(guò)16位精度會(huì)丟失
- 2.后面想到先把number數(shù)字正則篩選為string形式涡拘,然后再去parse轉(zhuǎn)換玲躯,這樣就能保證精準(zhǔn)度一樣
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)