1、假设要转换的list为:unitDetalJson ajax
1,在后台代码中将list变成json类型: json
JSONArray.fromObject(unitDetailList).toString() jsp
2,jsp的迭代代码为: spa
须要中eval转换 utf-8
$.each(eval(data.unitDetalJson), function (n, value) {
}); get
2、将list在后台迭代放到json里面,假设list为baseProjectList it
1,后台代码: io
getRequest().setCharacterEncoding("utf-8");
getResponse().setCharacterEncoding("utf-8"); function
JSONArray objs=new JSONArray(); 后台
for(int i=0;i<baseProjectList.size;i++){
JSONObject obj=new JSONObject();
obj.put("text",list.get(i).get(xx));
objs.add(obj);
}
getResponse().getWriter().println(objs.toString());
2,jsp代码
ajax({
data.xxx
})