去除js中的json存在的转义字符\
js中打印出的示例:执行console.log(JSON.stringify(d).toString()),得到以下信息:{"businessNumber":"HT-2019001","filesInfo":"[{\"fileName\":\"test.jpg\",\"groupName\":\"group1\",\"fdfsId\":\"M00/00/00/rBMBBERDSsG...
·
js中打印出的示例:
执行
console.log(JSON.stringify(d).toString()),得到以下信息:
{"businessNumber":"HT-2019001","filesInfo":"[{\"fileName\":\"test.jpg\",\"groupName\":\"group1\",\"fdfsId\":\"M00/00/00/rBMBBERDSsGAWFZFAAEe88kVsg8661.jpg\"},{\"fileName\":\"test02.sql\",\"groupName\":\"group1\",\"fdfsId\":\"M00/00/00/rBMAA12ENqmAERVQAAAfFFZ78oA526.sql\"}]"}
console.log(JSON.stringify(d).toString().replace(new RegExp("\\\\\"","gm"),"\"")),得到以下信息:
{"businessNumber":"HT-2019001","filesInfo":"[{"fileName":"test.jpg","groupName":"group1","fdfsId":"M00/00/00/rBMBBERDSsGAWFZFAAEe88kVsg8661.jpg"},{"fileName":"test02.sql","groupName":"group1","fdfsId":"M00/00/00/rBMAA12ENqmAERVQAAAfFFZ78oA526.sql"}]"}
结论:js中的json串出现单个反斜杠 \ 时,替换需要用 \\\\ 。
更多推荐
已为社区贡献1条内容
所有评论(0)