I'm make an API call with retrofit, the problem is the JSON I get from the call. Normally it was a simple Json with an array in it.
[
{
"herbID": 1,
"nameTrival": "Baldrian",
"nameWissenschaft": "Valeriana officinalis",
....
},
{
"herbID": 2,
"nameTrival": "Ringelblume",
"nameWissenschaft": "Calendula officinalis",
....
},
....
]
The new call looks like this
[
[
{
"nameTrival": "Baldrian",
"nameWissenschaft": "Valeriana officinalis",
"hoeheFrom": 20,
"hoeheTo": 200,
"familie": "Baldriangewaechse",
"pflanzentype": "Staude",
"auffaelligkeiten": "Je nach Standort sind die Fiederblätter schmäler oder breiter sowie dunkel- oder hellgrün, oft auch unterschiedlich geformt."
}
],
[
{
"standort": "Ufer"
},
{
"standort": "Graben"
},
{
"standort": "Wiesen"
},
{
"standort": "Waldrand"
}
],
[
{
"gebiet": "Nordeuropa"
},
{
"gebiet": "Südeuropa"
},
{
"gebiet": "Westeuropa"
},
{
"gebiet": "Osteuropa"
},
{
"gebiet": "Südosteuropa"
},
{
"gebiet": "Mitteleuropa"
},
{
"gebiet": "Südwesteuropa"
},
{
"gebiet": "Nordosteuoropa"
},
{
"gebiet": "Nordwesteuropa"
}
],
{
"fieldCount": 0,
"affectedRows": 0,
"insertId": 0,
"serverStatus": 34,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
]
I parsed the first Json with the following code
Call<List<Herb>> call = service.getAllHerbs();
call.enqueue(new Callback<List<Herb>>() {
@Override
public void onResponse(Call<List<Herb>> call, Response<List<Herb>> response) {
herbList = response.body();
loadDataList(herbList);
}
@Override
public void onFailure(Call<List<Herb>> call, Throwable t) {
Toast.makeText(PlantListActivity.this, "Unable to load herbs\nCheck your internet connection", Toast.LENGTH_LONG).show();
}
});
The new class looks like this
public class Herb{
ArrayList<Botanical> botanical;
ArrayList<Location> locations;
ArrayList<Area> areas;
public ArrayList<Botanical> getBotanical() {
return botanical;
}
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Area> getAreas() {
return areas;
}
}
With the new Json and the class it always fail with the error "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $"
Didn't I tell gson that the following is an array, after I declare them as an ArrayList? What is wrong with my class?
EDIT: The difference between the possible duplicate and my question is, that the other one has arrays with names. My json arrays doesn't have one, that's why I have a hard time parsing them.