2 回答

TA貢獻1946條經驗 獲得超3個贊
您可以使用 ObjectMapper 來轉換它。
public void testJackson() throws IOException {
ObjectMapper mapper = new ObjectMapper();
String json = "{"data": {"title": "Pool Party","date": {"start": "2018-08-14T15:44:44.625Z", "end": "2018-08-14T18:44:44.625Z"}}}";
TypeReference<HashMap<String,Object>> typeRef
= new TypeReference<HashMap<String,Object>>() {};
HashMap<String,Object> o = mapper.readValue(from, typeRef);
System.out.println("Got " + o);
}

TA貢獻1936條經驗 獲得超7個贊
嘗試這樣的事情:
public void testJackson() throws IOException {
ObjectMapper mapper = new ObjectMapper();
String json = "{\"data\": {\"title\": \"Pool Party\",\"date\": {\"start\":\"2018-08-14T15:44:44.625Z\", \"end\":\"2018-08-14T18:44:44.625Z\"}}}";
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
};
HashMap<String, Object> o = mapper.readValue(from, typeRef);
System.out.println("Got " + o);
}
添加回答
舉報