android - Not getting complete data from Json -
here trying json data url. oit displaying partial data. below details how reading data
bufferedinputstream is;
httpget httpget = new httpget(url); httpget.addheader("accept", "application/json"); httpresponse httpresponse = gethttpclient().execute(httpget); httpentity httpentity = httpresponse.getentity(); = new bufferedinputstream(httpentity.getcontent()) ; public void getjsonwithbytearray(bufferedinputstream istream) { bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream(); int ctr; try { ctr = istream.read(); while (ctr != -1) { bytearrayoutputstream.write(ctr); ctr = istream.read(); } istream.close(); } catch (ioexception e) { e.printstacktrace(); } log.v("text data", bytearrayoutputstream.tostring()); try { // parse data jsonobject original data in form of // json. jsonobject jobject = new jsonobject( bytearrayoutputstream.tostring()); jobj = jobject; log.v("jsonparser", "jsonbytearry data: " + jobj.tostring()); } catch (exception e) { e.printstacktrace(); } }
try method read response
public string getresponsebody(final httpentity entity) throws ioexception, parseexception { if (entity == null) { throw new illegalargumentexception("http entity may not null"); } inputstream instream = entity.getcontent(); if (instream == null) { return ""; } if (entity.getcontentlength() > integer.max_value) { throw new illegalargumentexception( "http entity large buffered in memory"); } stringbuilder buffer = new stringbuilder(); bufferedreader reader = new bufferedreader(new inputstreamreader(instream, http.utf_8)); string line = null; try { while ((line = reader.readline()) != null) { buffer.append(line); } } { instream.close(); reader.close(); } return buffer.tostring(); }
how use?
httpget httpget = new httpget(url); httpget.addheader("accept", "application/json"); httpresponse httpresponse = gethttpclient().execute(httpget); httpentity httpentity = httpresponse.getentity(); string response = getresponsebody(httpentity); try { // parse data jsonobject original data in form of // json. jsonobject jobject = new jsonobject( response); jobj = jobject; log.v("jsonparser", "jsonbytearry data: " + jobj.tostring()); } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment