问题复现场景:前端传参字符串数组,后端接收报错
后端代码示例
@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]]
文章来源:https://www.toymoban.com/news/detail-600937.html
解决方法
根据后端idea中提示,json解析错误。前端将数组转化成json推送,后端使用字符串接收再进行处理就可以解决。文章来源地址https://www.toymoban.com/news/detail-600937.html
到了这里,关于报错:参数导致JSON parse error: Cannot deserialize instance of `[Ljava.lang.String;` out of START_OBJECT to的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!