net.sf.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.een.entities.GeneralType.generals, no session or session was closed在用JSONObject.fromObject的时候,如果JavaBean中有Set等类型时,会报错hibernate的lazy的错,所以需要过虑掉那些无关的类型。直接贴代码: List<General> list = generalService.list(page, cid); if(list.size()>0){ json.put("status", "1"); json.put("msg", "获取成功"); }else{ json.put("status", "0"); json.put("msg", "暂无数据"); } JsonConfig config = new JsonConfig(); config.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object arg0, String arg1, Object arg2) { if (arg1.equals("generalType")) { return true; } else { return false; } } }); config.setExcludes(new String[] { "hibernateLazyInitializer", "handler", "tProvince" }); JSONArray jsonArray = JSONArray.fromObject(list, config); json.put("dataList", jsonArray); out.print(json); out.flush(); out.close(); 结果: {"status":"1","msg":"获取成功","dataList":[{"cnName":"中方供求信息","enName":"Financial","id":2,"sort":50},{"cnName":"6.18项目信息","enName":"Personal account","id":3,"sort":50},{"cnName":"欧盟供求信息","enName":"type","id":1,"sort":50}]}