scoreList = base.findAll("from ScoreVo"); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); JSONObject json = new JSONObject(); json.put("code",0); json.put("msg",""); json.put("count",0); json.put("data", scoreList); JSON.toJSONString(scoreList, SerializerFeature.DisableCircularReferenceDetect); System.out.println(json.toJSONString()); out.print(json.toJSONString()); out.flush(); out.close();
新手,使用了struts2和Hibernate,然后json格式输出就一直有问题,关闭重复检测也没有用,请大佬帮我看一下是什么问题
{"code":0,"count":0,"data":[{"course":{"courseId":1,"courseName":"C语言","credit":4},"courseId":1,"score":99,"scoreId":3,"stud":{"age":17,"clas":{"clasId":2,"clasName":"17秋2班","studs":[]},"clasId":2,"remark":"天方夜谭谷雨茶","sex":"女","studId":17010002,"studName":"晓晓"},"studId":17010002},{"course":{"courseId":4,"courseName":"JSP","credit":6},"courseId":4,"score":66,"scoreId":4,"stud":{"age":19,"clas":{"clasId":1,"clasName":"17秋1班","studs":[]},"clasId":1,"remark":"电饭锅和监控","sex":"男","studId":17010004,"studName":"李华"},"studId":17010004},{"course":{"courseId":2,"courseName":"SQL2014","credit":6},"courseId":2,"score":88,"scoreId":5,"stud":{"$ref":"$.data[4].stud"},"studId":17010002},{"course":{"courseId":3,"courseName":"JAVA","credit":8},"courseId":3,"score":78,"scoreId":7,"stud":{"$ref":"$.data[4].stud"},"studId":17010002},{"course":{"courseId":5,"courseName":"SSH","credit":10},"courseId":5,"score":45,"scoreId":8,"stud":{"age":24,"clas":{"$ref":"$.data[4].stud.clas"},"clasId":1,"remark":"3","sex":"男","studId":17010001,"studName":"东方饭店"},"studId":17010001}],"msg":""}
fastjson关闭??我记得流是需要关闭的吧,博主能重新叙述一下你得问题吗
抱歉,标题写错了,是关闭重复检测无效
@lss.24: 你这个json串没看出有什么问题,关闭重复检测无效能否叙述一下,或者错误信息贴出来
public static void OutJson(List list,int count){
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
try {
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
json.put("code", 0);
json.put("msg", 0);
json.put("count", count);
json.put("data", list);
String str = json.toJSONString(json,SerializerFeature.DisableCircularReferenceDetect);
System.out.println(str);
out.print(str);
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}