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