KarneeKarnay
Newbie
I'm working on an app where the user types in a game they are looking for and get information about the game back. One of the things I want to do is get the image of the game from this API I'm using. The problem I have is that I can't seem to retrieve the "image" JSONobject or cycle through it for the right image I want. Below is a copy of a search query limited to only images.
Below is a copy of the code I'm using.
Below is a copy of the code I'm using.
Code:
private void loadGameListJSON(String search) throws Exception
{
results = downloadGamesList("http://api.giantbomb.com/search/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=name,id,image,description&resources=game,concept&api_key=b0d8a8ba77b4308775bb3d3b7829f1339c4de9b8&format=json&offset=0");
System.out.println(results.toString());
results2 = downloadGamesList("http://api.giantbomb.com/reviews/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=score&api_key=b0d8a8ba77b4308775bb3d3b7829f1339c4de9b8&format=json");
System.out.println(results2.toString());
JSONObject jsonResults = new JSONObject(results);
JSONArray resultsArray = jsonResults.getJSONArray("results");
/*JSONObject jsonResults1 = new JSONObject(results1);
JSONArray resultsArray1 = jsonResults1.getJSONArray("image");*/
//JSONObject jsonResults1 = new JSONObject(results1);
//JSONArray resultsArray1 = jsonResults1.getJSONArray("results");
JSONObject jsonIMGResults = jsonResults.getJSONObject("image");
JSONObject jsonResults2 = new JSONObject(results2);
JSONArray resultsArray2 = jsonResults2.getJSONArray("results");
listItems = new ArrayList<String>();
int aLength = resultsArray.length();
//System.out.println(aLength);
int i;
for (i = 0; i < aLength; i++)
{
JSONObject j = (JSONObject) resultsArray.get(i);
String gameName = j.getString("name");
String gameID = j.getString("id");
String gameDescription = j.getString("description");
//JSONObject v = (JSONObject) resultsArray1.get(i);
//String gameImgURL = j.getString("thumb_url");
JSONObject q = (JSONObject) resultsArray2.get(i);
String gameScore = q.getString("score");
listItems.add(gameName + " : " + gameScore);
}
//Log.d("loop_check", "i = " + i);
//System.out.println(i);
handler.post(displayResultsRunnable);
}