如果是分页查询数据的话,首先将不必要的字段过滤了,如:currentPage,DetachedCriteria,pageSize.
通过以下代码完成
JsonConfig config = new JsonConfig(); ???????config.setExcludes(new String[]{"currentPage","dc","pageSize"}); ???????//将pageBean转化为json ???????String json = JSONArray.fromObject(pb,config).toString();
此时,返回的json数据是如下类型:
[ ???{ ???????"rows":[ ???????????{ ???????????????"decidedzones":[], ???????????????"deltag":"", ???????????????"haspda":"1" ???????????????,"id":"297e95de5ef6a63e015ef6ca27030000", ???????????????"name":"lsi", ???????????????"standard":"正常", ???????????????"station":"tudou", ???????????????"telephone":"18345678999" ???????????} ???????], ???????"total":4 ???}]
如果要想在页面中接收到数据必须要将最外层的中括号去了。我是通过求其子字符串完成的。如下:
json = json.substring(1, json.length()-1);
然后,将其写会页面中。
//帮pageBean写入页面中 ???????ServletActionContext.getResponse().setContentType("text/json;charset=utf-8"); ???????ServletActionContext.getResponse().getWriter().print(json); ???????return NONE;
如果,json中的key与easyui中datagrid的columns的field属性一致的话即可正确显示
使用easyui中的datagrid时,通过action能够返回json数据,但是,却不能在页面中显示数据
原文地址:http://www.cnblogs.com/empcl1314/p/7644372.html