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 trialkerdeseverin
9,688 PointsDifferent Json Data
I've completed the android videos and was attempting to use different json data. Can anyone tell me whats wrong with the code here. When I use the teamtreehouseblog link provided in the tutorials, the data is able to load. However when I use this link it does not.
URL storeUrl = new URL("http://strong-earth-32.heroku.com/stores");
HttpURLConnection connection = (HttpURLConnection) storeUrl.openConnection();
connection.connect();
respond = connection.getResponseCode();
Log.v(TAG,"Show Response: " + respond);
if(respond == HttpURLConnection.HTTP_OK){
InputStream Stream = connection.getInputStream();
Reader readstream = new InputStreamReader(Stream);
length = connection.getContentLength();
char[] contentArray = new char[length];
readstream.read(contentArray);
String data = new String(contentArray);
jsonValues = new JSONObject(data);
JSONObject jrespond = new JSONObject(data);
String status = jrespond.getString("stores");
Log.v(TAG,status);
JSONArray jsonPosts = jrespond.getJSONArray("name");
for(int i = 0; i< jsonPosts.length();i++){
JSONObject jsonpost = jsonPosts.getJSONObject(i);
String name = jsonpost.getString("name");
Log.v("name ",+ i + ":" + name);
}
1 Answer
kerdeseverin
9,688 PointsFigured it out based on this post: here
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherI got an email about this question and just came in to post that link. Glad you got it working!