JSONObject store = new JSONObject(response);
if(store.has("CreatedOn")) {
Timestamp stamp = new Timestamp(store.getLong("CreatedOn"));
Date date = new Date(stamp.getTime());
System.out.println(date);
}
或
JSONObject store = new JSONObject(response);
if(store.has("CreatedOn")) {
Integer datetimestamp = Integer.parseInt(store.getString("CreatedOn").replaceAll("\\D", ""));
Date date = new Date(datetimestamp);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
String dateFormatted = formatter.format(date);
}
考慮使用JSON方法,而不是包含。 JSON有「has()」,驗證key是否存在。
您還應該確保先嚐試{}抓住字符串,以確保其有效的JSON。
更新:
你的價值 /日期(1406192939581)/
這意味着它必須首先格式化。 通過解析字符串得到它
Integer datetimestamp = Integer.parseInt(store.getString("CreatedOn").replaceAll("\\D", ""));
更新了我的代碼。 –