加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

jsonobject将json格式字符串转化为对象时,日期格式错误解析

发布时间:2020-12-16 19:25:48 所属栏目:百科 来源:网络整理
导读:json格式字符串中的日期是按照‘yyyy-MM-dd HH:mm:ss’格式,如果按照常规的转换为对象,该日期则解析成当前系统时间 JSONObject json = JSONObject.fromObject(data);Dispatchplan dp = (Dispatchplan)JSONObject.toBean(json,Dispatchplan.class); 导致原

json格式字符串中的日期是按照‘yyyy-MM-dd HH:mm:ss’格式,如果按照常规的转换为对象,该日期则解析成当前系统时间

JSONObject json = JSONObject.fromObject(data);
Dispatchplan dp = (Dispatchplan)JSONObject.toBean(json,Dispatchplan.class);

导致原因JSONObject可能无法识别日期格式,做了以下修改就解决

Dispatchplan dp = new Dispatchplan();
JSONObject json = JSONObject.fromObject(data);
String[] dateFormats = new String[] {"yyyy-MM-dd HH:mm:ss"};  
JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats)); 		
dp = (Dispatchplan)JSONObject.toBean(json,Dispatchplan.class);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读