报错:HttpMessageNotReadableException: JSON parse error:Unrecognized token 'name': was expecting 'null'

3 篇文章 1 订阅

前台传速数据提示error里面的消息信息

控制台报如下消息提示:没有获取到前台传来的json数据

2019-09-10 23:01:01.743  WARN 10804 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: 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]]
2019-09-10 23:01:07.803  WARN 10804 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: 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]]

 截图图下

控制打印出消息提示,说明前台数据已经映射到改控制器上,只是没有获取到想要的参数

            $.ajax({
                url: url,
                type: "POST",
                data: json,
                dataType: "json",
                async: false,
                contentType: 'application/json;charset=utf-8',
                success: function (result) {

                    var newData = JSON.stringify(result);    //将json对象转换为字符串
                    newData = eval("(" + newData + ")");   //解析json
                    alert("消息:" + newData.msg);

                },
                error: function () {
                    alert("提交请求失败!");
                }
            });

将dataType: "json",中的传入数据,进行转化为json字符串即可

data: JSON.stringify(json),

后台接受controller为 @RequestBody JSONObject json

@RequestMapping(value = "/register", method = POST)
    public void register(@RequestBody JSONObject json,HttpServletResponse response) throws IOException {
        System.out.println(json.toString());
}

 

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值