{"new_terminal":{"term":2,"rows":40,"cols":185,"em_dimensions":{"w":7,"h":14.96875}}}
現在想把他轉換成一個嵌套著的Map。弄了好久都失敗了。
用的是jakeson,jar
@Test
public void testJson() {
ObjectMapper mapper = new ObjectMapper();
String str = "{\"new_terminal\":{\"term\":2,\"rows\":40,\"cols\":185,\"em_dimensions\":{\"w\":7,\"h\":14.96875}}}";
HashMap map;
try {
//readValue到一個原始數據類型.
map = mapper.readValue(str, HashMap.class);
System.out.println("map="+map);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
結果如下:map={new_terminal={term=2, rows=40, cols=185, em_dimensions={w=7, h=14.96875}}}