net.sf.json 格式化 Date
其他类型同理
Date 为格式化前 createDate":{"date":4,"day":2,"hours":17,"minutes":18,"month":7,"seconds":34,"time":1249377514000,"timezoneOffset":-480,"year":109}
JsonConfig cfg = new JsonConfig();
cfg.registerJsonValueProcessor(java.util.Date.class,new JsonValueProcessor() {
private final String format="yyyy-MM-dd";
public Object processObjectValue(String key, Object value,
JsonConfig arg2)
{
if(value==null)
return "";
if (value instanceof Date) {
String str = new SimpleDateFormat(format).format((Date) value);
return str;
}
return value.toString();
}
public Object processArrayValue(Object value, JsonConfig arg1)
{
return null;
}
});
JSONArray json = JSONArray.fromObject(a,cfg);