//下拉是json 解析
var comboStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url:'adminGroup', //这里是struts请求到action
method:'POST' //请求方式
}),
reader: new Ext.data.JsonReader({
//总记录数
totalProperty: 'results', //总记录数
root: 'items', //记录集合
id:'roleId'
},
['roleId','roleName'] //显示的两个字段
)
});
{"items":[{"password":"ahui","adminId":1,"role":{"roleName":"系统管理员","roleId":2,"sequence":"2","admin":null,"logoutMark":"否"},"adminName":"ahui","logout":"否"},{"password":"xiao","adminId":2,"role":{"roleName":"系统管理员","roleId":2,"sequence":"2","admin":null,"logoutMark":"否"},"adminName":"xiao","logout":"是"},"results":13}
这里是上面的格式
//下面是struts2里面的action代码 里面封装了ExtHelper工具类,里面有转换xml和json两种格式
public String findAll() throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
List list = groupService.getGroup(); //调用service里面的方法,把所有的数据都查询出来
String json = ExtHelper.getJsonFromList(list);//把list转换为json格式的数据
response.setContentType("text/json;charset=UTF-8");//设置数据到前台显示的字符编码,如果不转会有乱码
response.getWriter().write(json);
System.out.println(json);
return null;
}