我在前台是这样写的
int count = listUser.size(); // 求出总记录数
// total键 存放总记录数,必须的
jsonMap.put("total", count);
Gson gson=new Gson();
String gsonUser=gson.toJson(listUser);
jsonMap.put("rows", gsonUser);// rows键 存放每页记录 list
System.out.println(jsonMap);//打印正常
return "jsonMap";
打印出来的jsonMap是
{total=2, rows=[
s{"id":1,"name":"郭","password":"123","age":"21","sex":"女","phoneNumber":"151","department":"技术部","state":"1"},{"id":81,"name":"维","password":"152","age":"21","sex":"女","phoneNumber":"152","department":"技术部","state":"1"}]}
后台解析代码:
$(function(){
$('#dg').datagrid({
//url地址改为请求checkUserAction
url:'checkUserAction.action',
loadMsg:'Loading......',
queryParams:{type:''},
//width:300,
fitColumns:true,
striped:true,
nowrap:true,
singleSelect:true,
pagination:true,
rowStyler: function(index,row){
console.info("index" + index + "," + row)
},
但是控制台信息显示,解析情况如下,怎么会是一个字符一个字符的解析呀,
index0, [ send_query.action:32:21
index1,{ send_query.action:32:21
index2," send_query.action:32:21
index3,i send_query.action:32:21
index4,d send_query.action:32:21
index5," send_query.action:32:21
index6,: send_query.action:32:21
index7,1 send_query.action:32:21
index8,, send_query.action:32:21
index9," send_query.action:32:21
index10,n send_query.action:32:21
index11,a send_query.action:32:21
index12,m send_query.action:32:21
index13,e send_query.action:32:21
index14," send_query.action:32:21
哎呦喂,又是你啊,哈哈……………… ,一般前台解析json串用JSON.stringify()吧
嘻嘻,缘分,我不太会用这个,方便加下扣扣跟我说吗?
啊对了,扣扣是1457054547