Recently I started developing a app that searches and API to find a game your looking for. A friend of mine lent me his twitter project to edit so I could make my own. I've been modifying it, but the problem I'm having right now is that the for loop is not returning the searched game.
The image below is an example of what the JSONParser should be getting if the user searched Far Cry 3.
The problem I think is that the for loop is not returning the name value and I currently have no idea why. Anyone know what my problem is?
[HIGH] private void loadTweetsJSON(String search) throws Exception
{
results = downloadTweets("http://api.giantbomb.com/search/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=name,id&resources=game,concept&api_key=1234556789&format=json&offset=0");
System.out.println(results.toString());
JSONObject jsonResults = new JSONObject(results);
JSONArray resultsArray = jsonResults.getJSONArray("results");
listItems = new ArrayList<String>();
for (int i = 0; i < resultsArray.length(); i++)
{
JSONObject j = (JSONObject) resultsArray.get(i);
listItems.add(j.getString("name") + ": " + j.getString("text"));
}
handler.post(displayResultsRunnable);
}
[/HIGH]
EDIT: A quick update. After debugging the for loop I've noticed that the int i value never increases. This leads me to believe that the code is searching through the "results" array, but it is failing to find the value of my search string. Which in this case would be Far Cry 3. Once again though I'm not sure why it's doing this.
The image below is an example of what the JSONParser should be getting if the user searched Far Cry 3.
The problem I think is that the for loop is not returning the name value and I currently have no idea why. Anyone know what my problem is?
[HIGH] private void loadTweetsJSON(String search) throws Exception
{
results = downloadTweets("http://api.giantbomb.com/search/?query=" + URLEncoder.encode(search, "UTF-8") + "&field_list=name,id&resources=game,concept&api_key=1234556789&format=json&offset=0");
System.out.println(results.toString());
JSONObject jsonResults = new JSONObject(results);
JSONArray resultsArray = jsonResults.getJSONArray("results");
listItems = new ArrayList<String>();
for (int i = 0; i < resultsArray.length(); i++)
{
JSONObject j = (JSONObject) resultsArray.get(i);
listItems.add(j.getString("name") + ": " + j.getString("text"));
}
handler.post(displayResultsRunnable);
}
[/HIGH]
EDIT: A quick update. After debugging the for loop I've noticed that the int i value never increases. This leads me to believe that the code is searching through the "results" array, but it is failing to find the value of my search string. Which in this case would be Far Cry 3. Once again though I'm not sure why it's doing this.