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 trialRakesh Saini
4,270 PointsRetrieving JSON data
Im working on JSON data that does not provide me content-length so i have tried the second option of getting the JSON content without getting the content-length HttpResponse response = client.execute(httpget); StatusLine statusLine = response.getStatusLine(); responseCode = statusLine.getStatusCode();
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());
Log.i(TAG, "successful HTTP response data:" + jsonResponse);
}
else {
Log.i(TAG, String.format("Unsuccessful HTTP response code: %d", responseCode));
}
now the problem is i dont get the complete content showing in Log.i in logcat . its just shows total 25 Characters which is incomplete data when i debug it i get the below information builder = {java.lang.StringBuilder@831724340992}"{"data":{"campaigns":[]}}" value = {char[26]@831724485904} shared = true count = 25 if someone could please help me in finding out what is wrong over here.
Rakesh Saini
4,270 Points@miguelcastro2 I new to this could please explain what exactly do mean by endpoint.
miguelcastro2
Courses Plus Student 6,573 PointsWhat is the URL of the JSON you are trying to download? The request to this URL should provide a value content length.
Rakesh Saini
4,270 PointsNever mind i fixed it thanks :)
miguelcastro2
Courses Plus Student 6,573 Pointsmiguelcastro2
Courses Plus Student 6,573 PointsA valid HTTP request should contain the content length. What is your JSON endpoint?