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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM