java - This code will get only first value from json string -


please me out need display json array data show first value json .i tried change values 1 value shown not array

 @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     button btnadd=(button)findviewbyid(r.id.btnhit);     tvdata = (textview)findviewbyid(r.id.tvjsonitem);     btnadd.setonclicklistener(             new view.onclicklistener() {                 @override                 public void onclick(view v) {                     new jsontask().execute("https://api.myjson.com/bins/106o37");                 }             }     );  } 

public class jsontask extends asynctask{

    @override     protected string doinbackground(string... params) {         httpsurlconnection connection = null;         bufferedreader reader = null;         try {             url url = new url(params[0]);             connection = (httpsurlconnection) url.openconnection();             connection.connect();             inputstream stream = connection.getinputstream();             reader = new bufferedreader(new inputstreamreader(stream));             stringbuffer buffer = new stringbuffer();             string line = "";             while ((line = reader.readline()) != null) {                 buffer.append(line);              }              string finaljson = buffer.tostring();             jsonarray jsonarray = new jsonarray(finaljson);              stringbuffer finalbuffereddata=new stringbuffer();             for(int i=0; i<jsonarray.length(); i++){                 jsonobject obj = jsonarray.getjsonobject(i);                 string description = obj.getstring("description");                 finalbuffereddata.append(description + "\t\n"                                              );                 return finalbuffereddata.tostring();             }          } catch (malformedurlexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         } catch (jsonexception e) {             e.printstacktrace();         } {             if (connection != null) {                 connection.disconnect();             }             try {                 if (reader != null) {                     reader.close();                 }             } catch (ioexception e) {                 e.printstacktrace();             }         }         return null;     } 

your return statement should outside of loop. inside method returns first value.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -