Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Blog Reader Android App Adapting Data for Display in a List Adding Secondary Data with a SimpleAdapter

Trying a diffrent JSON url than of teamtreehouse and app gives me the Oops! Sorry message all the time

Hi Ben and all,

I changed "http://blog.teamtreehouse.com/api/get_recent_summary/?count=20" to another public JSON url for wearther forecasting, this one : "http://api.openweathermap.org/data/2.5/weather?q=rome,it"

so I changed "posts" to "weather" in order to get the weather JSON array. I changed: KEY_TITLE = "title" to KEY_TITLE = "main" KEY_AUTHOR = "author" to KEY_AUTHOR = "description"

that way I didn't have to change anything else on the code to test it out.

Is there any other secret to JSON parsing that I might not aware of? Can't find the reason of why this is not working.

Thanks in advance for your help, John

1 Answer

As Ben pointed out in this treehouse post, use this code instead:

if (responseCode == HttpURLConnection.HTTP_OK) {
    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
    String line;
    while((line = reader.readLine()) != null){
        builder.append(line);
    }

    jsonResponse = new JSONObject(builder.toString());
}
else {
    Log.i(TAG, String.format("Unsuccessful HTTP response code: %d", responseCode));
}