系列文章目录
问题关于json 字符串中带有反斜杠的问题
一、 原因
前端在使用了两次stringify({}) 才会出现反斜杠,由于后端要求要传入一个对象和两个字符串,都要是json类型,对象是动态创建的。
二、使用步骤
1.代码示例
代码如下(示例):
let goodsMap = new Map()
for (var i = 0; i < that.myChartList.length; i++) {
goodsMap.set(
that.myChartList[i].goods.id.toString(),
that.myChartList[i].amount.toString()
)
}
let obj = Object.create(null)
for (let [k, v] of goodsMap) {
obj[k] = v
}
goodsMap = JSON.stringify(obj).replace(/[\]/g, ‘’)
console.log(goodsMap)
that.$axios
.post(
'/order/alipayGroup',
JSON.stringify({
address: t