0 0

JSON日期转换问题0

 public static Object getEntity(String jsonString, Class clazz) {

    //① 设定日期转换格式

    JSONUtils.getMorpherRegistry().registerMorpher(

        new DateMorpher(new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss",

            "yyyy-MM" }));

    JSONObject jsonObject = null;

    try {

      jsonObject = JSONObject.fromObject(jsonString);

    } catch (Exception e) {

      e.printStackTrace();

    }

    return JSONObject.toBean(jsonObject, clazz);

  }

 

main{

   String str="{'name':'007','age','18','birthday':'2013-08-03','sex',''}";

   MyEntity myEntity=(MyEntity)getEntity(str,myEntity);

   System.out.println(myEntity.getBirthday().toLocalString());

   //按理说我上面也给出了日期的转换格式  但是有时候还是会出现日期为当前日期的可能性  求大神指教

 

}

 

 


问题补充:忘记还有一列了:
String str="{'name':'007','age','18','birthday':'2013-08-03','sex','','','textfield-1145-inputEl',''}";
2013年8月08日 08:57

2个答案 按时间排序 按投票排序

0 0

不知道楼主用的什么JSON转换工具,貌似看楼主的代码应该是没问题的

2013年8月08日 21:05
0 0

仔细检查下代码,我测试过没有问题的。

2013年8月08日 14:09

相关推荐

Global site tag (gtag.js) - Google Analytics