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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |