List <SoftwareDownloadCount> softWares = softWareService. softWareList (user );
JSONObject json = new JSONObject ();
JsonConfig config = new JsonConfig ();
Config. setIgnoreDefaultExcludes (false );
Config. setCycleDetectionStrategy (CycleDetectionStrategy. LENIENT );
Config. registerJsonValueProcessor (Date. class, new JsonDateValueProcessor (JsonDateValueProcessor. TIME_FORMAT); // date processor register
JSONArray joson = JSONArray. fromObject (softWares, config );
Return ajaxJson (joson. toString ());
Import java. text. SimpleDateFormat;
Import java. util. Date;
Import java. util. Locale;
Import net. sf. json. JsonConfig;
Import net. sf. json. processors. JsonValueProcessor;
/**
* JSON date format processing (converting java to JSON)
* @ Author sailor
*/
Public class JsonDateValueProcessor implements JsonValueProcessor {
/**
* DatePattern
*/
Private String datePattern = "yyyy-MM-dd ";
// Long Date Format
Public static String TIME_FORMAT = "yyyy-MM-dd HH: mm: ss ";
// The long date format is accurate to milliseconds.
Public static String LONG_TIME_FORMAT = "yyyy-MM-dd HH: mm: ss SSS ";
/**
* JsonDateValueProcessor
*/
Public JsonDateValueProcessor (){
Super ();
}
/**
* @ Param format
*/
Public JsonDateValueProcessor (String format ){
Super ();
This. datePattern = format;
}
/**
* @ Param value
* @ Param jsonConfig
* @ Return Object
*/
Public Object processArrayValue (Object value, JsonConfig jsonConfig ){
Return process (value );
}
/**
* @ Param key
* @ Param value
* @ Param jsonConfig
* @ Return Object
*/
Public Object processObjectValue (String key, Object value,
JsonConfig jsonConfig ){
Return process (value );
}
/**
* Process
* @ Param value
* @ Return
*/
Private Object process (Object value ){
Try {
If (value instanceof Date ){
SimpleDateFormat sdf = new SimpleDateFormat (datePattern,
Locale. UK );
Return sdf. format (Date) value );
}
Return value = null? "": Value. toString ();
} Catch (Exception e ){
Return "";
}
}
/**
* @ Return the datePattern
*/
Public String getDatePattern (){
Return datePattern;
}
/**
* @ Param pDatePattern the datePattern to set
*/
Public void setDatePattern (String pDatePattern ){
DatePattern = pDatePattern;
}
}