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串出现单个反斜杠 \ 时,替换需要用 \\\\ 。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐