I have a JSON similar to this which I get it by sending HTTP request.
{
"0": {
"name": "Chunk",
"type": "magic",
"item": "Chestplate",
"item_min_lvl": "70",
"id": {
"health": "0.3",
"spell": "24%",
"life": "0.1",
"xp": "24%",
"loot": "22%"
},
"def": "67"
},
"1": {
"name": "Thor",
"type": "normal",
"item": "Shoe",
"item_min_lvl": "12",
"id": {
"xp": "24%"
},
"def": "12"
},
"2": {
"name": "Clipper",
"type": "normal",
"item": "Sword",
"item_min_lvl": "51",
"id": {
"health": "1",
"life": "0.12",
"xp": "4%"
},
"min_dam": "11",
"max_dam": "7"
}
}
Here is my code:
java.lang.reflect.Type type = new TypeToken<ArrayList<Map<String, Object>>>(){}.getType();
ArrayList<Map<String, Object>> list = gson.fromJson(json, type);//Error here
for(Map<String, Object> m : list)
{
//blah
}
It returns this error Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2
Can anyone help me to solve this error? I am new to JSON and GSON. Please note, some of the the "items" aren't the same so I have to use TypeToken.