你可以这样做:
public class MonthTree {
private int id;
private String logo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
@Override
public String toString() {
return "MonthTree [id=" + id + ", logo=" + logo + "]";
}
public static void main(String[] args) {
String json = "{\n" +
" \"A\": [\n" +
" {\n" +
" \"id\": 16,\n" +
" \"logo\": \"QJQSZzbXurElfHYcq6hcbPuaWKVfQU31lx2eSIIr.png\"\n" +
" },\n" +
" {\n" +
" \"id\": 20,\n" +
" \"logo\": \"AizaZzbXurElfHYcq6PuaWKV2761lx2eSLESASFr.png\"\n" +
" }\n" +
" ],\n" +
" \"B\": [\n" +
" {\n" +
" \"id\": 42,\n" +
" \"logo\": \"tBYhHGTNTCYT60RZJydMyGgg47Tla36ISuRj4p0e.png\"\n" +
" },\n" +
" {\n" +
" \"id\": 44,\n" +
" \"logo\": \"kCZveUWo9eqIZc25deE4ln8llxlbBviRolk4PsCm.png\"\n" +
" }\n" +
" ]\n" +
"}";
try {
ObjectMapper mapper = new ObjectMapper();
Map<String, List<MonthTree>> map = mapper.readValue(json, new TypeReference<Map<String, List<MonthTree>>>(){});
Iterator<String> it = map.keySet().iterator();
while (it.hasNext()) {
String letter = (String) it.next();
List<MonthTree> list = map.get(letter);
for (MonthTree monthTree : list) {
System.out.println("Letter: "+letter+" MonthTree: "+monthTree);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}