2 Replies - 1756 Views - Last Post: 02 October 2017 - 03:08 PM

#1 atul92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-October 17

how to send arraylist to server using retrofit 2?

Posted 02 October 2017 - 02:27 PM

i'm currently developing an app which requires to post array list to server in order to save that data in the database . i have tried searching for the solutions on stackoverflow and asked many bloggers,youtubers but still the code kept getting error and iam unable to solve the problem till now,as my code is really long so instead iam posting the github link , please go through the link and let me know what i can do in order to make the app funciton properly.


Point to remember :-
1.)don't tell me to switch library and do it as i want the app to be as small(in memory size)as possible
2.)don't tell me to switch to kotlin, i don't intend to as my whole app is done in java and this is final piece of the app
3.)don't tell me to use some other variable than json object as i have already tried and failed


AND FINALLY
here is the link to my project on github:-
https://github.com/atul92cs/Sqlite4

please go through and help me out by anyway u can

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: how to send arraylist to server using retrofit 2?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: how to send arraylist to server using retrofit 2?

Posted 02 October 2017 - 02:30 PM

Are you getting an error? If so copy/paste it entirely here... as well as the relevant code it is happening at.
Was This Post Helpful? 0
  • +
  • -

#3 atul92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-October 17

Re: how to send arraylist to server using retrofit 2?

Posted 02 October 2017 - 03:08 PM

View Postmodi123_1, on 02 October 2017 - 02:30 PM, said:

Are you getting an error? If so copy/paste it entirely here... as well as the relevant code it is happening at.


this the error iam getting:-
errorgoogle.gson.JsonSyntaxException:java.lang.illegalStateException:Expected BEGIN_OBJECT but was STRING at line 1 column1 path$

this is the code which i think is causing the problem:-
   private void loadCart()
    {


        Cursor cursor = dbHelper.getCarProducts();
        cursor.moveToFirst();
        do {

            JSONObject product = new JSONObject();
            try {
                product.put("Sellerid",cursor.getString(cursor.getColumnIndex("_Sellerid")));
                product.put("ProductCost",cursor.getString(cursor.getColumnIndex("_Cost")));
                product.put("ProductQuantity",cursor.getString(cursor.getColumnIndex("_Quantity")));
                product.put("ProductPrice",cursor.getString(cursor.getColumnIndex("_Price")));
                product.put("ProductName",cursor.getString(cursor.getColumnIndex("_Name")));
                userCart.put(product);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }while(cursor.moveToNext());
             Cart = new JSONObject();
          try
          {
              Cart.put("OrderSummary",userCart.toString());
          }
          catch (Exception ex)
          {

}
}



points:- 1.)i have tried removing to string method and send the data but its not working
2.)iam not posting the whole code as its very lengthy , if you want to go through the whole you can go the link and seeit
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1