日期:2014-05-16  浏览次数:20357 次

java对象与json字符串转换
Date date = new Date();
JSONObject dataJsonObj = JSONObject.fromObject(date);
String dataJsonStr = dataJsonObj.toString();
System.out.println(dataJsonStr);
		
JSONObject jsonObj = JSONObject.fromObject(dataJsonStr);
Date myDate = (Date) JSONObject.toBean(jsonObj, Date.class);
System.out.println(myDate);
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
String myDateStr = dateFormat.format(myDate);
System.out.println(myDateStr);