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

前台传速数据提示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());
}

 

你可能感兴趣的:(java,jquery)