I am having a very tough time deserializing json in java with gson.
I have the following json:
{"races":[
{"id":1,"mask":1,"side":"alliance","name":"Human"},
{"id":2,"mask":2,"side":"horde","name":"Orc"},
{"id":3,"mask":4,"side":"alliance","name":"Dwarf"}]}
The java code I have now is:
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Gson gson = new Gson();
Type type = new TypeToken<List<WoWDetails>>(){}.getType();
List<WoWRaces> races = gson.fromJson(response, type);
for (WoWRaces race : races){
if(raceID.equals(race.id)) {
raceName = race.name;
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
errorMSG = (TextView) findViewById(R.id. textView5);
errorMSG.setText("That didn't work! URL: \n"+error);
errorMSG.setVisibility(View.VISIBLE);
}
});
In WoWRaces.java is the following code:
WoWRaces.java
public class WoWRaces {
public Integer id;
public String name;
}
It's giving me the following error:
Expected BEGIN_ARRAY but was BEGIN_OBJECT
I have searched and visited multiple questions but I can't seem to figure this out. The data that I would need is the id and the name bound to it.
Thank you in advance