您当前的位置: 首页 >  qq_34412985 ar

com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘xxx‘:

qq_34412985 发布时间:2021-12-22 10:53:53 ,浏览量:5

jquery ajax代码

        $.ajax({
            type:"post",
            url:"/webswmm/runModel",
            dataType:'json',
            contentType:"application/json;charset=UTF-8",
            data:{name:'goatling'},
            async:true,
            success:function (data) {
                removeLoading('test');
                showAlertDiologue("success","run");
                resultUrl=data;
            },
            error:function () {
                removeLoading('test');
                showAlertDiologue("fail","run");
            }
        });

        @RequestMapping("/webswmm/runModel")
        @ResponseBody
        public JSONArray runModel(@RequestBody JSONObject jsonObject)
        {
     
            return dataService.runModel(jsonObject);
        }

报错:

    JSON parse error: Unrecognized token 'name': was expecting 'null', 'true', 'false' or NaN; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting 'null', 'true', 'false' or NaN
     at [Source: (PushbackInputStream); line: 1, column: 6]

原因:

{name:'goatling'} 这种形式根本不是标准JSON字符串

  '{"name":"goatling"}'  这个才是标准JSON字符串

改正后:

        $.ajax({
            type:"post",
            url:"/webswmm/runModel",
            dataType:'json',
            contentType:"application/json;charset=UTF-8",
            data:'{"name":"goatling"}',
            async:true,
            success:function (data) {
                removeLoading('test');
                showAlertDiologue("success","run");
                resultUrl=data;
            },
            error:function () {
                removeLoading('test');
                showAlertDiologue("fail","run");
            }
        });

这样才能成功在后台接收到。
我的是因为

body.bPointInfo.requestInfo.body:undefined使用@RequestBody注解直接转实体时报错

关注
打赏
查看更多评论

qq_34412985

暂无认证

  • 5浏览

    0关注

    957博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录