java.util.Date 转json 时格式问题
在将java.util.Date 类型字段转为json时,获取时取到的为[object object],解决方法为:在讲对象转化为json格式是添加自定义的日期格式转化类,具体代码如下:
HttpServletResponse response = this.getHttpResponse();response.setContentType("text/plain;charset=UTF-8");response.setHeader("Cache-Control","no-cache");JsonConfig jsonConfig = new JsonConfig();jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));try {response.getWriter().print(JSONObject.fromObject(conObj,jsonConfig));} catch (Exception e) {e.printStackTrace();}return null;