I'm new to Java and programming for Android and I've seen a lot of tutorials but I am kinda clueless atm on how to loop through a JSONObject and set it to my class.
Example of JSON data: http://sickbeard.com/api/#history
Class I made:
public Episode(JSONObject obj) {
try {
this.id = Integer.parseInt(obj.getString("episode").toString());
this.tvId = Integer.parseInt(obj.getString("tvdbid").toString());
this.resource = obj.getString("resource").toString();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
I came as far as this...
ArrayList<Episode> episodeList = new ArrayList<Episode>();
JSONObject data = new JSONObject();
for(int i = 0; i < 2; i++) {
try {
data = response.getJSONObject("data");
episodeList.add(new Episode(data));
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
// for each entry create new episode :)
} else {
return null;
}
responseis, nor why you even have that for-loop in place.