Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'XXXX': was expecting ('true', 'false' or 'null')

这个问题是因为前端传值有问题

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");
}
});
这样才能成功在后台接收到。

posted @ 2020-06-18 19:43  你快乐我亦心安  阅读(2881)  评论(0编辑  收藏  举报