首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

json数组中的日期在页面怎么显示

2012-02-24 
json数组中的日期在页面如何显示{date:18,day:3,hours:0,minutes:0,month:0,nanos:0,seconds

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 一般都是用这个。

热点排行