I have a JSON response representing a Band that looks like this:
[
{
"Picture": {
"Small": "someurl
"Medium": "someurl",
"Large": "someurl",
"XLarge": "someurl"
},
"Name": "Tokyo Control Tower",
"Guid": "TCT",
"ID": 15
}
]
And I'm trying to use GSON to deserialize it into a class called SearchResults which contains a list of Bands. My SearchResults and Band classes look like this:
public class SearchResults {
public List<Band> results;
}
public class Band {
@SerializedName("Name")
public String name;
@SerializedName("Guid")
public String guid;
@SerializedName("ID")
public Integer id;
@SerializedName("Picture")
List<Photo> pictures;
}
In my code I try to convert the json string like this:
protected void onPostExecute(String result) {
Gson gson = new Gson();
SearchResults results = gson.fromJson(result, SearchResults.class);
Band band = results.results.get(0);
bandName.setText(band.name);
}
When I run this code, I get an error from GSON saying Expected BEGIN_OBJECT but was BEGIN_ARRAY. Any ideas on how to fix?
picturesis a list in your class definition (i.e. a JSON array), but it's a JSON object in the sample JSON you gave. Did you meant to either make it an array in the JSON, or create a "Pictures" class or map to represent the various picture sizes?