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
})