首页 > 基础资料 博客日记

报错:参数导致JSON parse error: Cannot deserialize instance of `[Ljava.lang.String;` out of START_OBJECT to

2023-07-24 18:30:01基础资料围观719

文章报错:参数导致JSON parse error: Cannot deserialize instance of `[Ljava.lang.String;` out of START_OBJECT to分享给大家,欢迎收藏Java资料网,专注分享技术知识

问题复现场景:前端传参字符串数组,后端接收报错

后端代码示例

    @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推送,后端使用字符串接收再进行处理就可以解决。


文章来源:https://blog.csdn.net/weixin_45372531/article/details/128966193
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!

标签:

相关文章

本站推荐

标签云