JSON Object help


Last Updated:

  1. KarneeKarnay

    KarneeKarnay Member

    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.

    [​IMG]

    Below is a copy of the code I'm using.

    Code (Text):
    1.  
    2. private void loadGameListJSON(String search) throws Exception
    3.     {
    4.         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");    
    5.         System.out.println(results.toString());
    6.        
    7.         results2 = downloadGamesList("http://api.giantbomb.com/reviews/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=score&api_key=b0d8a8ba77b4308775bb3d3b7829f1339c4de9b8&format=json");
    8.         System.out.println(results2.toString());
    9.        
    10.         JSONObject jsonResults = new JSONObject(results);
    11.         JSONArray resultsArray = jsonResults.getJSONArray("results");
    12.        
    13.         /*JSONObject jsonResults1 = new JSONObject(results1);
    14.         JSONArray resultsArray1 = jsonResults1.getJSONArray("image");*/
    15.        
    16.         //JSONObject jsonResults1 = new JSONObject(results1);
    17.         //JSONArray resultsArray1 = jsonResults1.getJSONArray("results");
    18.         JSONObject jsonIMGResults = jsonResults.getJSONObject("image");
    19.        
    20.         JSONObject jsonResults2 = new JSONObject(results2);
    21.         JSONArray resultsArray2 = jsonResults2.getJSONArray("results");
    22.        
    23.         listItems = new ArrayList<String>();
    24.        
    25.         int aLength = resultsArray.length();
    26.        
    27.         //System.out.println(aLength);
    28.        
    29.         int i;
    30.        
    31.         for (i = 0; i < aLength; i++)
    32.         {
    33.             JSONObject j = (JSONObject) resultsArray.get(i);
    34.             String gameName = j.getString("name");
    35.             String gameID = j.getString("id");
    36.             String gameDescription = j.getString("description");
    37.            
    38.             //JSONObject v = (JSONObject) resultsArray1.get(i);
    39.             //String gameImgURL = j.getString("thumb_url");
    40.            
    41.             JSONObject q = (JSONObject) resultsArray2.get(i);
    42.             String gameScore = q.getString("score");
    43.            
    44.             listItems.add(gameName + " : " + gameScore);
    45.  
    46.         }
    47.        
    48.         //Log.d("loop_check", "i = " + i);
    49.         //System.out.println(i);
    50.        
    51.         handler.post(displayResultsRunnable);
    52.     }
    53.  

    Advertisement
  2. uchat

    uchat Member

Share This Page