Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus Player | Nexus 9
test: Reply
LinkBack Thread Tools
Old January 2nd, 2013, 09:14 AM   #1 (permalink)
Junior Member
Thread Author (OP)
Join Date: Dec 2012
Posts: 15
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default JSON Object help

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.

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");    	
    	results2 = downloadGamesList("http://api.giantbomb.com/reviews/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=score&api_key=b0d8a8ba77b4308775bb3d3b7829f1339c4de9b8&format=json");
    	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();
    	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); 

KarneeKarnay is offline  
Reply With Quote
sponsored links
Old January 9th, 2013, 11:21 AM   #2 (permalink)
New Member
Join Date: Jan 2013
Posts: 12
Device(s): LG 2X,HTC One V
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts

Not exactly answering your question, but I think you might want to know about alternative.

I no loger use JSONObject since I found GSON is a lot easier to use and harder to make mistake. The newer version of GSON can be integrated in android app without any problem. See google-gson - A Java library to convert JSON to Java objects and vice-versa - Google Project Hosting
uchat is offline  
Reply With Quote

Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 12:08 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.