Json array to url in android -


my json array code ...

 private jsonarray getresults() {      string mypath = "/data/data/com.example.sebastian.patientdetails/databases/" + "mydbname.db";      string mytable = "patients";       sqlitedatabase mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly);      string searchquery = "select  * " + mytable;     cursor cursor = mydatabase.rawquery(searchquery, null);      jsonarray resultset = new jsonarray();      cursor.movetofirst();     while (!cursor.isafterlast()) {          int totalcolumn = cursor.getcolumncount();         jsonobject rowobject = new jsonobject();          (int = 0; < totalcolumn; i++) {             if (cursor.getcolumnname(i) != null) {                 try {                     if (cursor.getstring(i) != null) {                         log.d("tag_name", cursor.getstring(i));                         rowobject.put(cursor.getcolumnname(i), cursor.getstring(i));                     } else {                         rowobject.put(cursor.getcolumnname(i), "");                     }                 } catch (exception e) {                     log.d("tag_name", e.getmessage());                 }             }         }         resultset.put(rowobject);         cursor.movetonext();     }     cursor.close();     log.d("tag_name", resultset.tostring());     return resultset; } 

how can sent json array url connect web application? should need convert json array.? or how can it? how can solve it.

you can post entire json array(resultset) php server using networking library. @ php side, decode json array , save value per need. give code in used retrofit 2 library:

create interface:

public interface yourapi{  @formurlencoded  @post("add_to_db.php")  call<responsebody> insertserver(@field("options") string jsonarray); } 

create class apiclient:

private static final string base_url ="http://yoururl.com/"; private static retrofit retrofit = null;  public static retrofit getclient() {      if (retrofit == null) {         retrofit = new retrofit.builder()                 .baseurl(base_url)                 .client(client)                 .addconverterfactory(gsonconverterfactory.create())                 .build();     }     return retrofit; } 

in main activity:

yourapi itemapi= apiclient.getclient().create(yourapi.class);                     call<responsebody> servercall=itemapi.insertserver(string.valueof(resultset)); 

servercall.enqueue(new constants.backoffcallback(retrynum) { @override public void onresponse(call call, response response) { bufferedreader reader; string output = "";

                            try {                                 reader = new bufferedreader(new inputstreamreader(response.body().bytestream()));                                 output = reader.readline();                                 log.e("tag",""+output);                             } catch (ioexception e) {                                 e.printstacktrace();                             }                         @override                         public void onfailedafterretry(throwable t) {                         }                     }); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -