1. Are you ready for the Galaxy S20? Here is everything we know so far!

JSON Object help

Discussion in 'Android Development' started by KarneeKarnay, Jan 2, 2013.

  1. KarneeKarnay

    KarneeKarnay Newbie
    Thread Starter

    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.  
     


  2. uchat

    uchat Newbie

Loading...
Similar Threads - JSON Object help
  1. gmrcs
    Replies:
    1
    Views:
    836
  2. beginnerProgrammer
    Replies:
    0
    Views:
    438
  3. Dinakar
    Replies:
    0
    Views:
    449
  4. anirudha
    Replies:
    0
    Views:
    472
  5. Rascalsailor
    Replies:
    2
    Views:
    485
  6. Chin Chun Seong
    Replies:
    0
    Views:
    384
  7. Korsholm
    Replies:
    0
    Views:
    269
  8. Jay Roa
    Replies:
    2
    Views:
    4,038
  9. mark9
    Replies:
    5
    Views:
    527
  10. darth_daniel
    Replies:
    9
    Views:
    1,385

Share This Page

Loading...