问题复现场景:前端传参字符串数组,后端接收报错
后端代码示例
@RequestMapping(value = "/setOptUserIdByCommentId", method = RequestMethod.POST)
@ApiOperation("设置分办人")
public void setOptUserIdByCommentId(@RequestBody String[] commentIds, String optUserId, String optUserName) {
....
}
前端代码示例
this.$axios({
method: "post",
url: "/jd/comment/setOptUserIdByCommentId",
data: {
commentids: ids,
optuserid: encodeURI(this.handleUserValue[1]),
optusername: encodeURI(this.optusername)
},
}).then((res) => {
if (res.data.status == 0) {
this.$message.error(res.data.msg)
return
}
this.$message.success('设置成功!')
this.dialogVisible = false;
});
后端警告内容:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of [Ljava.lang.String;
out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of [Ljava.lang.String;
out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]]
解决方法
根据后端idea中提示,json解析错误。前端将数组转化成json推送,后端使用字符串接收再进行处理就可以解决。