Can not deserialize instance of java.lang.String out of START_OBJECT token

无法反序列化

11:30:14,382 ERROR AbstractController:201 - Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@1d843f1; line: 1, column: 61] (through reference chain: cn.ql.module.projectPerson.domain.MkAppraisal["schoolReason"]); nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

 

前台是传的json串

{"mkId":"402881aa3e4a50f3013e4a8d473504db","schoolScore":"3","schoolReason":{"length":1,"0":{},"context":{"jQuery17209899038962966509":130,"location":{}},"selector":"#school_reason"}}

 

后台是拿实体类接收

//添加推荐
	@RequestMapping(value = "addMkAppraisal",produces = "application/json;charset=UTF-8")
	public void addMkAppraisal(@RequestBody MkAppraisal mkAppraisal,ModelMap model){
		model.clear();
		try
		{
			mkAppraisalBiz.save(mkAppraisal);
			model.addAttribute("status", "success");
		} catch (BizException e)
		{
			log.info(e.getMessage());
			model.addAttribute("status", e.getMessage());
		} catch (Exception e)
		{
			log.error(e.getMessage(),e);
			model.addAttribute("status", e.getMessage());
		}
	}

 

实体类中schoolReason是String类型的,

把前台传的json串alert出来,发现的问题,取值取得不对,

 

//添加推荐
function addAppraisal(){
	var mkAppraisal = new Object();
	mkAppraisal.mkId=$("#mk_id").val();
	mkAppraisal.schoolScore=$("#school_score").val();
	mkAppraisal.schoolReason=$("#school_reason").text();
	if(mkAppraisal.schoolScore == "" || isNaN(mkAppraisal.schoolScore) || parseInt(mkAppraisal.schoolScore) < 1 || parseInt(mkAppraisal.schoolScore) > 100){
		alert("请正确输入评分");
		return;
	}
	if(mkAppraisal.schoolReason == ""){
		alert("请输入推荐理由");
		return;
	}
	alert(JSON.stringify(mkAppraisal));
	$.ajaxPost(JSON.stringify(mkAppraisal),base+"/mkAppraisal/addMkAppraisal.json",saveSuccess,error); //通过
}
	
function saveSuccess(data, textStatus){
   if (data.status=="success") {
		alert("推荐成功!");
		cancelWin();
   } else if(data.status == "fail"){
	   alert("推荐失败!\n"+data.error);
   } else {
	   alert("推荐失败!\n"+data.status);
   } 
}

function error(data){
	alert('错误', "推荐失败!"+data);
}

 

页面引入的ajax.js,$.ajaxPost方法在他里边

<!-- crud ajax wrap-->    
<script type="text/javascript" src="${baseStatic}/common/js/ajax.js"></script>

 

 

你可能感兴趣的:(deserialize,START_OBJECT)