1. 程式人生 > >集合和JSON裝換

集合和JSON裝換

     //使用json-lib將PageBean物件轉為json,通過輸出流寫回頁面中

              //JSONObject---將單一物件轉為json

               //JSONArray----將陣列或者集合物件轉為json

注:需要將引用型別的去掉,否則會報錯,迴圈引用

	public String findAll() throws IOException{
		List<BcStaff> list=staffService.findAll();
		JsonConfig config = new JsonConfig();
		config.setExcludes(new String[]{"qpWorkbills","qpNoticebills","qpNoticebills_1","bcDecidedzones","qpWorkbills_1","bcDecidedzones_1"});
		String listString = JSONArray.fromObject(list,config).toString();
		ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
		ServletActionContext.getResponse().getWriter().print(listString);
		return NONE;
	}