在客户端我有:
var data = new FormData();
data.append('users', [{ name: "John"}] );
data.append('excel', files[0]);
console.log(data);
$.ajax({
url: 'url',
type: 'POST',
data: data,
cache: false,
processData: false,
contentType: false,
服务器上的下一个中间件:
app.use(bodyParser.json({limit:1024*1024}));
app.use(bodyParser.urlencoded());
app.use(multer());
但是当我发送somthing我有文件但没有解析JSON正文时,它看起来像:
{ users: '[object Object]' }
答案 0 :(得分:0)
我认为你应该显示控制器代码。但是根据你在评论中所说的内容。
如果我使用JSON.stringify([{name:“John”}]),我将拥有此{users:'[{“name”:“John”}]'}
使用:
JSON.stringify([{ name: "John"}])
然后在接收端:
{ users: JSON.parse('[{"name":"John"}]') }
对收到的数据使用JSON.parse
。
所以现在你: