1. 程式人生 > >JSON轉化物件時,日期字串轉化為Date

JSON轉化物件時,日期字串轉化為Date

JSONObject jsonObject=JSONObject.fromObject(contract);
String[] dateFormats = new String[] {"yyyy-MM-dd"};  
//註冊日期轉化格式
JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats)); 		
//json字串轉化為java物件
Map map = new HashMap();
map.put("tmptype", TMMPInfo.class); 
map.put("extaList", TMMPExta.class); 
TMPersonalHotContract tmpCcontract=(TMPersonalHotContract)JSONObject.toBean(jsonObject, TMPersonalHotContract.class,map);
return tmpCcontract;