Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting ('true', 'false' or 'null')ajax
參數有問題,不能解析成json對象spring
ajax提交添加下面兩行代碼json
contentType:'application/json;charset=utf-8'
data:JSON.stringify(數據)後端
var allData = {
name:"張三",
age:20
};
$.ajax({ type: "POST", url: "xxxx", contentType:'application/json;charset=utf-8', data:JSON.stringify(allData), success: function (data) { alert(data); } });
注意:app
後端若是用springMVC的@RequestBody註解的話,則只能Json對象的字符串,不能接收Json對象,用 JSON.stringify(data)的方式將對象變成字符串,同時ajax請求也要指定dataType: "json",contentType:"application/json" ,這樣就能用@RequestBody註解綁定對象或者List集合.url