写项目的时候遇到的问题。jSONException.
原因是因为我的返回字段带日期格式。
因为我前台所需的内容不需要日期,在此就把日期忽略了。如果前台需要日期信息,此种方法不可取。
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[] { "createTime", "updDate" });
map.put("key","value");
JSONObject jsonmap = JSONObject.fromObject(map, jsonConfig);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
try {
response.getWriter().write(jsonmap.toString());
response.getWriter().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}