日期:2014-05-17  浏览次数:20663 次

json数组中的日期在页面如何显示
{"date":18,"day":3,"hours":0,"minutes":0,"month":0,"nanos":0,"seconds":0,"time":1326816000000,"timezoneOffset":-480,"year":112}
在页面显示为[object Object]
如何在页面格式化为日期字符串呢
请各位高手指点一下,在线等

------解决方案--------------------
LZ 可以在后台转换成josn格式的时候 把日期同时格式化
Java code

TestJson t=new TestJson();
        t.setDt(new Date());
        t.setName("json");
        JsonConfig config=new JsonConfig();
        config.registerJsonValueProcessor("dt", new JsonValueProcessor() {
            
            @Override
            public Object processObjectValue(String key, Object value, JsonConfig arg2) {
                // TODO Auto-generated method stub
                //yyyy-MM-dd 你想要的日期格式
                SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
                return sd.format(value);
            }
            @Override
            public Object processArrayValue(Object arg0, JsonConfig arg1) {
                // TODO Auto-generated method stub
                return null;
            }
        });
        JSONObject obj=JSONObject.fromObject(t, config);
        System.out.println(obj.toString());

------解决方案--------------------
在后台先转换吧。
我一般在javabean 中日期返回String 把日期先格式化
------解决方案--------------------
JsonConfig 一般都是用这个。