1. 2015 is going to be a great year for Android! Why wait??
    Samsung Galaxy Note 5 | Samsung Galaxy S6 | HTC One M9
  2. New Forum Created: Samsung Gear VR!

JSON Object help


  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):

    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);
        }
     

    Advertisement
    :
  2. uchat

    uchat Member

Loading...

Share This Page