前台将实体对象以json串形式传到后台并解析

js代码:

var rowVal ={'content':content,'happen':happen,'adjustment':adjustment,
'checktime':checktime,'checkpeople':checkpeople,'againpeople':againpeople,
'checkcompany':checkcompany,'remark':remark};

var rowStr =JSON.stringify(rowVal);

dataStr ="dataArr="+eval('('+JSON.stringify(dataArr.toString())+')');

$.ajax({
url:"<%=path%>/Check/add.do",
type:"POST",
dataType:"JSON",
data:dataStr,
//traditional:true,
success:function(data){
alert(data.msg)
},
error:function(){
alert(data.msg)
}
})

java后台接受:

@ResponseBody
@RequestMapping("addSupervise")
public Map addSupervise(@RequestParam String dataArr){

System.out.println(dataArr);//收到一个json形式的字符串{"key":"value"},{"key":"value"},{"key":"value"},{"key":"value"}

}

解析json串的方法是以“}”拆分字符串,用Gson包的方法循环处理得到每个对象。————over

你可能感兴趣的:(json)