在 formdata 追加期间如何不使用字符串到对象数组?

how can i get without use string to array of object during formdata append?

我想通过 formdata append 发送对象数据数组。我正在向后端服务器获取一个数组,但是关闭字符串'[]'会出现一个对象数组,比如 this.so 我想删除这个 selfclose 字符串。所以请帮助我,我该如何解决这个问题?

我要这个......

varientDetails: ['{"index":0.40051008889580997,"sort":"45","sku":"5","waightorquantity":"100","Unit":"ghg","mrp":"gj","discount":"iy","price":"","stock":"","minstock":"","outofstock":""}']

但我想要这样的数据:

varientDetails: [{"index":0.40051008889580997,"sort":"45","sku":"5","waightorquantity":"100","Unit":"ghg","mrp":"gj","discount":"iy","price":"","stock":"","minstock":"","outofstock":""}]

我正在使用这种方法

varientDetails.forEach(varient => {
  formData.append(`varientDetails[]`, JSON.stringify(varient))
})

FormData 无法发送文字 JavaScript 对象。它可以发送...

USVString or Blob (including subclasses such as File)

您的对象必须序列化为 JSON,这正是您正在做的。要在服务器上处理它,您需要解析它们。假设您使用的是 Multer 之类的东西,并且 non-file 字段在 req.body...

上可用
const variantDetails = req.body.varientDetails.map(json => JSON.parse(json))