jsonobject.tobean date的解决办法

时间:2023-01-18 21:44:48
[java]  view   copy
  1. if(zhongdJsonArr!=null&&zhongdJsonArr.size()>0){  
  2.     for (int i = 0; i < zhongdJsonArr.size(); i++) {  
  3.         entry = zhongdJsonArr.getJSONObject(i);  
  4.         //控制java.util.date  
  5.         String[] dateFormats = new String[]{"yyyy-MM-dd HH:mm:ss"};  
  6.         JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats));  
  7.                               
  8.                               
  9.         KmGmZhongduaninfo info = (KmGmZhongduaninfo)JSONObject.toBean(entry, KmGmZhongduaninfo.class);  
  10.   
  11.         zhongduanService.addOrModifyOrDelZhongduan(info,Integer.parseInt(syncType));  
  12.     }  
  13.   
  14.     jsonObject.put("resCode"200);  
  15.     jsonObject.put("resDesc""处理成功!");  
  16.   
  17. }  

关键代码:

//控制java.util.date
String[] dateFormats = new String[]{"yyyy-MM-dd HH:mm:ss"};

JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats));


ConvertUtils.register(new DateTimeConverter(), java.util.Date.class);