I have a problem creating a mapping for json that I want to parse with json. This is very specific, this is about a json file with a json array with objects in it.
my jsonfile starts as follows:
[
{
"venue": {
"venue_seasons": [
{
"created_at": "2011-12-25T23:00:28Z",
"updated_at": "2011-12-28T15:13:53Z",
"start_timestamp": 1293840000,
"id": 337,
"end": "2011-12-24T00:00:00Z",
"enabled": true,
"start": "2011-01-01T00:00:00Z",
"season_openings": [ … ],
"end_timestamp": 1324684800
},
{ … }
],
"address": "someadress",
"city": "cityname",
"name": "name",
"created_at": "2011-03-31T07:55:33Z",
etcetera
}
"venue":{another venue
So, first an array than an object (place) with a large number of objects in it (I deleted most of them because it is not important for my question) and some arrays (for example, season_openings).
My syntax code works like this: im uses gson. The input stream is working fine.
Reader reader = new InputStreamReader(inputStream);
JsonResponse venueResponse = gson.fromJson(reader, JsonResponse.class);
List<Venues> results = venueResponse.venue;
with the JsonResponse class:
public class JsonResponse {
public List<Venues> venue;
}
and Venues.class:
public class Venues {
public List<VenueSeasons> venue_seasons;
@SerializedName("adress")
public String getAdress;
@SerializedName("city")
public String getCity;
@SerializedName("country")
public String getCountry; etcetera
}
But when I run this code, I get an error message:
Unable to start activity ComponentInfo{com.hera.android.JSON/com.hera.android.JSON.TestParser2Activity}: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
, : , . jsonresponse.class json- json ( , jsonfile). .
, , - , , ?
.