json date转化

增加此类

 

public class DateJsonValueProcessor implements JsonValueProcessor{

	private final String format="yyyy-MM-dd";
	public Object processArrayValue(Object arg0, JsonConfig arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	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();
	}

}

 

json调用

JsonConfig cfg = new JsonConfig();   
		cfg.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor()) ;
		
		JSONArray  jsonArray = JSONArray.fromObject(list,cfg);
 

 

你可能感兴趣的:(json)