how to Post data in an array in android using retrofit 2












0















i am facing a problem regarding posting data in an array in android using retrofit 2. i have to post the data of nearly 14 fields in my profile setting activity ...
Like this ...



name="basics[first_name] , name="basics[last_name]" , name="basics[phone_number]"


i have to send data in this format. i am not understanding how to do it need help.i am not understanding how to make Call of the api in the interface because i have to put data in an array.
Currently i am doing it like this but i know its not right...



@FormUrlEncoded
@POST("profile_setting/basic_setting")
Call<ResponseBody> UpdateBasics(
@Query("user_id") int user_id ,
@Field("nickname") String nickname ,
@Field("first_name") String first_name ,
@Field("last_name") String last_name ,
@Field("phone_number") String phone_number ,
@Field("fax") String fax
);









share|improve this question























  • show your url of API. except the domain name.

    – Sushil Kumar
    Nov 22 '18 at 6:22













  • themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

    – S.H
    Nov 22 '18 at 6:26











  • it is a POST Request

    – S.H
    Nov 22 '18 at 6:27











  • have you checked on POSTMAN ?

    – Sushil Kumar
    Nov 22 '18 at 6:28






  • 1





    @SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

    – Ali Ahmed
    Nov 22 '18 at 6:35
















0















i am facing a problem regarding posting data in an array in android using retrofit 2. i have to post the data of nearly 14 fields in my profile setting activity ...
Like this ...



name="basics[first_name] , name="basics[last_name]" , name="basics[phone_number]"


i have to send data in this format. i am not understanding how to do it need help.i am not understanding how to make Call of the api in the interface because i have to put data in an array.
Currently i am doing it like this but i know its not right...



@FormUrlEncoded
@POST("profile_setting/basic_setting")
Call<ResponseBody> UpdateBasics(
@Query("user_id") int user_id ,
@Field("nickname") String nickname ,
@Field("first_name") String first_name ,
@Field("last_name") String last_name ,
@Field("phone_number") String phone_number ,
@Field("fax") String fax
);









share|improve this question























  • show your url of API. except the domain name.

    – Sushil Kumar
    Nov 22 '18 at 6:22













  • themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

    – S.H
    Nov 22 '18 at 6:26











  • it is a POST Request

    – S.H
    Nov 22 '18 at 6:27











  • have you checked on POSTMAN ?

    – Sushil Kumar
    Nov 22 '18 at 6:28






  • 1





    @SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

    – Ali Ahmed
    Nov 22 '18 at 6:35














0












0








0








i am facing a problem regarding posting data in an array in android using retrofit 2. i have to post the data of nearly 14 fields in my profile setting activity ...
Like this ...



name="basics[first_name] , name="basics[last_name]" , name="basics[phone_number]"


i have to send data in this format. i am not understanding how to do it need help.i am not understanding how to make Call of the api in the interface because i have to put data in an array.
Currently i am doing it like this but i know its not right...



@FormUrlEncoded
@POST("profile_setting/basic_setting")
Call<ResponseBody> UpdateBasics(
@Query("user_id") int user_id ,
@Field("nickname") String nickname ,
@Field("first_name") String first_name ,
@Field("last_name") String last_name ,
@Field("phone_number") String phone_number ,
@Field("fax") String fax
);









share|improve this question














i am facing a problem regarding posting data in an array in android using retrofit 2. i have to post the data of nearly 14 fields in my profile setting activity ...
Like this ...



name="basics[first_name] , name="basics[last_name]" , name="basics[phone_number]"


i have to send data in this format. i am not understanding how to do it need help.i am not understanding how to make Call of the api in the interface because i have to put data in an array.
Currently i am doing it like this but i know its not right...



@FormUrlEncoded
@POST("profile_setting/basic_setting")
Call<ResponseBody> UpdateBasics(
@Query("user_id") int user_id ,
@Field("nickname") String nickname ,
@Field("first_name") String first_name ,
@Field("last_name") String last_name ,
@Field("phone_number") String phone_number ,
@Field("fax") String fax
);






java android retrofit retrofit2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 6:18









S.HS.H

548




548













  • show your url of API. except the domain name.

    – Sushil Kumar
    Nov 22 '18 at 6:22













  • themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

    – S.H
    Nov 22 '18 at 6:26











  • it is a POST Request

    – S.H
    Nov 22 '18 at 6:27











  • have you checked on POSTMAN ?

    – Sushil Kumar
    Nov 22 '18 at 6:28






  • 1





    @SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

    – Ali Ahmed
    Nov 22 '18 at 6:35



















  • show your url of API. except the domain name.

    – Sushil Kumar
    Nov 22 '18 at 6:22













  • themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

    – S.H
    Nov 22 '18 at 6:26











  • it is a POST Request

    – S.H
    Nov 22 '18 at 6:27











  • have you checked on POSTMAN ?

    – Sushil Kumar
    Nov 22 '18 at 6:28






  • 1





    @SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

    – Ali Ahmed
    Nov 22 '18 at 6:35

















show your url of API. except the domain name.

– Sushil Kumar
Nov 22 '18 at 6:22







show your url of API. except the domain name.

– Sushil Kumar
Nov 22 '18 at 6:22















themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

– S.H
Nov 22 '18 at 6:26





themographics.com/wordpress/doc_api/wp-json/api/v1/… this is the URL for the setting @SushilKumar

– S.H
Nov 22 '18 at 6:26













it is a POST Request

– S.H
Nov 22 '18 at 6:27





it is a POST Request

– S.H
Nov 22 '18 at 6:27













have you checked on POSTMAN ?

– Sushil Kumar
Nov 22 '18 at 6:28





have you checked on POSTMAN ?

– Sushil Kumar
Nov 22 '18 at 6:28




1




1





@SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

– Ali Ahmed
Nov 22 '18 at 6:35





@SushilKumar i'm not saying its wrong. i'm talking about better approach. i believe its easy to post data as single object rather than 14 variables.

– Ali Ahmed
Nov 22 '18 at 6:35












3 Answers
3






active

oldest

votes


















0














Do this way to send Json Object as request parameters using Retrofit 2



    @Headers("Content-Type: application/json")
@POST("profile_setting/basic_setting")
Call<ResponseBody> UpdateBasics(@Body String body);


This is how you would use the above method to send json object



try {
JSONObject paramObject = new JSONObject();
paramObject.put(value_one, "field_one"));
paramObject.put(value_second, "field_second"));
Call<ResponseBody> userCall = apiInterface.UpdateBasics(paramObject.toString());
userCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//handle your result here

}

@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
//handle failure
}
});
} catch (JSONException e) {
e.printStackTrace();
}





share|improve this answer
























  • hello... what is this value_one , value_second here? @Quicklearner

    – S.H
    Nov 22 '18 at 7:13













  • your request params, like name

    – Quick learner
    Nov 22 '18 at 9:23











  • first_name, last_name etc

    – Quick learner
    Nov 22 '18 at 9:24



















0














Make a class



public class Basic {
public final int user_id;
public final String nickname;
....

public Basic(int user_id, ...) {

}
}


Then pass list of objects of this class to this interface



public interface MyService {
@POST("/basic")
Response void sendData(@Body List<Basic> basic);
}


Or you can do the same with JSONObject. Just make a list of jsonobjects



JSONObject paramObject = new JSONObject();
paramObject.put(value_one, "field_one"));
paramObject.put(value_second, "field_second"));


put the objects in a list



list.add(paramObject);


then pass to the retrofit



public interface MyService {
@POST("/basic")
Response void sendJsonObjectData(@Body List<JSONObject> basic);
}





share|improve this answer































    0














    You can follow this was. (posting how i've done that)



    @POST("Users.json")
    Call<UploadData> uploadToken(@Body UploadData uploadData);


    UploadData.class



    public class UploadData {

    private String DeviceToken, DeviceIMEI;

    public UploadData(String deviceToken, String deviceIMEI) {
    DeviceToken = deviceToken;
    DeviceIMEI = deviceIMEI;
    }

    public String getDeviceToken() {
    return DeviceToken;
    }

    public String getDeviceIMEI() {
    return DeviceIMEI;
    }
    }


    Then in your Activity



    private void uploadToken() {
    ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
    UploadData uploadToken = new UploadData(deviceToken, imei);
    final Call<UploadData> callUpload = apiInterface.uploadToken(uploadToken);

    callUpload.enqueue(new Callback<UploadData>() {
    @Override
    public void onResponse(Call<UploadData> call, Response<UploadData> response) {
    if (response.isSuccessful()) {
    Toasty.success(Main.this, "Token Uploaded !! ", Toast.LENGTH_LONG).show();
    }
    }

    @Override
    public void onFailure (Call < UploadData > call, Throwable t){
    call.cancel();
    Toasty.error(Main.this, "Error: " + t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }
    });

    }





    share|improve this answer
























    • i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

      – S.H
      Nov 22 '18 at 7:06











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424919%2fhow-to-post-data-in-an-array-in-android-using-retrofit-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Do this way to send Json Object as request parameters using Retrofit 2



        @Headers("Content-Type: application/json")
    @POST("profile_setting/basic_setting")
    Call<ResponseBody> UpdateBasics(@Body String body);


    This is how you would use the above method to send json object



    try {
    JSONObject paramObject = new JSONObject();
    paramObject.put(value_one, "field_one"));
    paramObject.put(value_second, "field_second"));
    Call<ResponseBody> userCall = apiInterface.UpdateBasics(paramObject.toString());
    userCall.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
    //handle your result here

    }

    @Override
    public void onFailure(Call<LoginResponse> call, Throwable t) {
    //handle failure
    }
    });
    } catch (JSONException e) {
    e.printStackTrace();
    }





    share|improve this answer
























    • hello... what is this value_one , value_second here? @Quicklearner

      – S.H
      Nov 22 '18 at 7:13













    • your request params, like name

      – Quick learner
      Nov 22 '18 at 9:23











    • first_name, last_name etc

      – Quick learner
      Nov 22 '18 at 9:24
















    0














    Do this way to send Json Object as request parameters using Retrofit 2



        @Headers("Content-Type: application/json")
    @POST("profile_setting/basic_setting")
    Call<ResponseBody> UpdateBasics(@Body String body);


    This is how you would use the above method to send json object



    try {
    JSONObject paramObject = new JSONObject();
    paramObject.put(value_one, "field_one"));
    paramObject.put(value_second, "field_second"));
    Call<ResponseBody> userCall = apiInterface.UpdateBasics(paramObject.toString());
    userCall.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
    //handle your result here

    }

    @Override
    public void onFailure(Call<LoginResponse> call, Throwable t) {
    //handle failure
    }
    });
    } catch (JSONException e) {
    e.printStackTrace();
    }





    share|improve this answer
























    • hello... what is this value_one , value_second here? @Quicklearner

      – S.H
      Nov 22 '18 at 7:13













    • your request params, like name

      – Quick learner
      Nov 22 '18 at 9:23











    • first_name, last_name etc

      – Quick learner
      Nov 22 '18 at 9:24














    0












    0








    0







    Do this way to send Json Object as request parameters using Retrofit 2



        @Headers("Content-Type: application/json")
    @POST("profile_setting/basic_setting")
    Call<ResponseBody> UpdateBasics(@Body String body);


    This is how you would use the above method to send json object



    try {
    JSONObject paramObject = new JSONObject();
    paramObject.put(value_one, "field_one"));
    paramObject.put(value_second, "field_second"));
    Call<ResponseBody> userCall = apiInterface.UpdateBasics(paramObject.toString());
    userCall.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
    //handle your result here

    }

    @Override
    public void onFailure(Call<LoginResponse> call, Throwable t) {
    //handle failure
    }
    });
    } catch (JSONException e) {
    e.printStackTrace();
    }





    share|improve this answer













    Do this way to send Json Object as request parameters using Retrofit 2



        @Headers("Content-Type: application/json")
    @POST("profile_setting/basic_setting")
    Call<ResponseBody> UpdateBasics(@Body String body);


    This is how you would use the above method to send json object



    try {
    JSONObject paramObject = new JSONObject();
    paramObject.put(value_one, "field_one"));
    paramObject.put(value_second, "field_second"));
    Call<ResponseBody> userCall = apiInterface.UpdateBasics(paramObject.toString());
    userCall.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
    //handle your result here

    }

    @Override
    public void onFailure(Call<LoginResponse> call, Throwable t) {
    //handle failure
    }
    });
    } catch (JSONException e) {
    e.printStackTrace();
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 '18 at 6:34









    Quick learnerQuick learner

    2,5551925




    2,5551925













    • hello... what is this value_one , value_second here? @Quicklearner

      – S.H
      Nov 22 '18 at 7:13













    • your request params, like name

      – Quick learner
      Nov 22 '18 at 9:23











    • first_name, last_name etc

      – Quick learner
      Nov 22 '18 at 9:24



















    • hello... what is this value_one , value_second here? @Quicklearner

      – S.H
      Nov 22 '18 at 7:13













    • your request params, like name

      – Quick learner
      Nov 22 '18 at 9:23











    • first_name, last_name etc

      – Quick learner
      Nov 22 '18 at 9:24

















    hello... what is this value_one , value_second here? @Quicklearner

    – S.H
    Nov 22 '18 at 7:13







    hello... what is this value_one , value_second here? @Quicklearner

    – S.H
    Nov 22 '18 at 7:13















    your request params, like name

    – Quick learner
    Nov 22 '18 at 9:23





    your request params, like name

    – Quick learner
    Nov 22 '18 at 9:23













    first_name, last_name etc

    – Quick learner
    Nov 22 '18 at 9:24





    first_name, last_name etc

    – Quick learner
    Nov 22 '18 at 9:24













    0














    Make a class



    public class Basic {
    public final int user_id;
    public final String nickname;
    ....

    public Basic(int user_id, ...) {

    }
    }


    Then pass list of objects of this class to this interface



    public interface MyService {
    @POST("/basic")
    Response void sendData(@Body List<Basic> basic);
    }


    Or you can do the same with JSONObject. Just make a list of jsonobjects



    JSONObject paramObject = new JSONObject();
    paramObject.put(value_one, "field_one"));
    paramObject.put(value_second, "field_second"));


    put the objects in a list



    list.add(paramObject);


    then pass to the retrofit



    public interface MyService {
    @POST("/basic")
    Response void sendJsonObjectData(@Body List<JSONObject> basic);
    }





    share|improve this answer




























      0














      Make a class



      public class Basic {
      public final int user_id;
      public final String nickname;
      ....

      public Basic(int user_id, ...) {

      }
      }


      Then pass list of objects of this class to this interface



      public interface MyService {
      @POST("/basic")
      Response void sendData(@Body List<Basic> basic);
      }


      Or you can do the same with JSONObject. Just make a list of jsonobjects



      JSONObject paramObject = new JSONObject();
      paramObject.put(value_one, "field_one"));
      paramObject.put(value_second, "field_second"));


      put the objects in a list



      list.add(paramObject);


      then pass to the retrofit



      public interface MyService {
      @POST("/basic")
      Response void sendJsonObjectData(@Body List<JSONObject> basic);
      }





      share|improve this answer


























        0












        0








        0







        Make a class



        public class Basic {
        public final int user_id;
        public final String nickname;
        ....

        public Basic(int user_id, ...) {

        }
        }


        Then pass list of objects of this class to this interface



        public interface MyService {
        @POST("/basic")
        Response void sendData(@Body List<Basic> basic);
        }


        Or you can do the same with JSONObject. Just make a list of jsonobjects



        JSONObject paramObject = new JSONObject();
        paramObject.put(value_one, "field_one"));
        paramObject.put(value_second, "field_second"));


        put the objects in a list



        list.add(paramObject);


        then pass to the retrofit



        public interface MyService {
        @POST("/basic")
        Response void sendJsonObjectData(@Body List<JSONObject> basic);
        }





        share|improve this answer













        Make a class



        public class Basic {
        public final int user_id;
        public final String nickname;
        ....

        public Basic(int user_id, ...) {

        }
        }


        Then pass list of objects of this class to this interface



        public interface MyService {
        @POST("/basic")
        Response void sendData(@Body List<Basic> basic);
        }


        Or you can do the same with JSONObject. Just make a list of jsonobjects



        JSONObject paramObject = new JSONObject();
        paramObject.put(value_one, "field_one"));
        paramObject.put(value_second, "field_second"));


        put the objects in a list



        list.add(paramObject);


        then pass to the retrofit



        public interface MyService {
        @POST("/basic")
        Response void sendJsonObjectData(@Body List<JSONObject> basic);
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 6:36









        NIKHIL MAURYANIKHIL MAURYA

        1319




        1319























            0














            You can follow this was. (posting how i've done that)



            @POST("Users.json")
            Call<UploadData> uploadToken(@Body UploadData uploadData);


            UploadData.class



            public class UploadData {

            private String DeviceToken, DeviceIMEI;

            public UploadData(String deviceToken, String deviceIMEI) {
            DeviceToken = deviceToken;
            DeviceIMEI = deviceIMEI;
            }

            public String getDeviceToken() {
            return DeviceToken;
            }

            public String getDeviceIMEI() {
            return DeviceIMEI;
            }
            }


            Then in your Activity



            private void uploadToken() {
            ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
            UploadData uploadToken = new UploadData(deviceToken, imei);
            final Call<UploadData> callUpload = apiInterface.uploadToken(uploadToken);

            callUpload.enqueue(new Callback<UploadData>() {
            @Override
            public void onResponse(Call<UploadData> call, Response<UploadData> response) {
            if (response.isSuccessful()) {
            Toasty.success(Main.this, "Token Uploaded !! ", Toast.LENGTH_LONG).show();
            }
            }

            @Override
            public void onFailure (Call < UploadData > call, Throwable t){
            call.cancel();
            Toasty.error(Main.this, "Error: " + t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
            }
            });

            }





            share|improve this answer
























            • i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

              – S.H
              Nov 22 '18 at 7:06
















            0














            You can follow this was. (posting how i've done that)



            @POST("Users.json")
            Call<UploadData> uploadToken(@Body UploadData uploadData);


            UploadData.class



            public class UploadData {

            private String DeviceToken, DeviceIMEI;

            public UploadData(String deviceToken, String deviceIMEI) {
            DeviceToken = deviceToken;
            DeviceIMEI = deviceIMEI;
            }

            public String getDeviceToken() {
            return DeviceToken;
            }

            public String getDeviceIMEI() {
            return DeviceIMEI;
            }
            }


            Then in your Activity



            private void uploadToken() {
            ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
            UploadData uploadToken = new UploadData(deviceToken, imei);
            final Call<UploadData> callUpload = apiInterface.uploadToken(uploadToken);

            callUpload.enqueue(new Callback<UploadData>() {
            @Override
            public void onResponse(Call<UploadData> call, Response<UploadData> response) {
            if (response.isSuccessful()) {
            Toasty.success(Main.this, "Token Uploaded !! ", Toast.LENGTH_LONG).show();
            }
            }

            @Override
            public void onFailure (Call < UploadData > call, Throwable t){
            call.cancel();
            Toasty.error(Main.this, "Error: " + t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
            }
            });

            }





            share|improve this answer
























            • i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

              – S.H
              Nov 22 '18 at 7:06














            0












            0








            0







            You can follow this was. (posting how i've done that)



            @POST("Users.json")
            Call<UploadData> uploadToken(@Body UploadData uploadData);


            UploadData.class



            public class UploadData {

            private String DeviceToken, DeviceIMEI;

            public UploadData(String deviceToken, String deviceIMEI) {
            DeviceToken = deviceToken;
            DeviceIMEI = deviceIMEI;
            }

            public String getDeviceToken() {
            return DeviceToken;
            }

            public String getDeviceIMEI() {
            return DeviceIMEI;
            }
            }


            Then in your Activity



            private void uploadToken() {
            ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
            UploadData uploadToken = new UploadData(deviceToken, imei);
            final Call<UploadData> callUpload = apiInterface.uploadToken(uploadToken);

            callUpload.enqueue(new Callback<UploadData>() {
            @Override
            public void onResponse(Call<UploadData> call, Response<UploadData> response) {
            if (response.isSuccessful()) {
            Toasty.success(Main.this, "Token Uploaded !! ", Toast.LENGTH_LONG).show();
            }
            }

            @Override
            public void onFailure (Call < UploadData > call, Throwable t){
            call.cancel();
            Toasty.error(Main.this, "Error: " + t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
            }
            });

            }





            share|improve this answer













            You can follow this was. (posting how i've done that)



            @POST("Users.json")
            Call<UploadData> uploadToken(@Body UploadData uploadData);


            UploadData.class



            public class UploadData {

            private String DeviceToken, DeviceIMEI;

            public UploadData(String deviceToken, String deviceIMEI) {
            DeviceToken = deviceToken;
            DeviceIMEI = deviceIMEI;
            }

            public String getDeviceToken() {
            return DeviceToken;
            }

            public String getDeviceIMEI() {
            return DeviceIMEI;
            }
            }


            Then in your Activity



            private void uploadToken() {
            ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
            UploadData uploadToken = new UploadData(deviceToken, imei);
            final Call<UploadData> callUpload = apiInterface.uploadToken(uploadToken);

            callUpload.enqueue(new Callback<UploadData>() {
            @Override
            public void onResponse(Call<UploadData> call, Response<UploadData> response) {
            if (response.isSuccessful()) {
            Toasty.success(Main.this, "Token Uploaded !! ", Toast.LENGTH_LONG).show();
            }
            }

            @Override
            public void onFailure (Call < UploadData > call, Throwable t){
            call.cancel();
            Toasty.error(Main.this, "Error: " + t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
            }
            });

            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 6:43









            Ali AhmedAli Ahmed

            1,3411314




            1,3411314













            • i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

              – S.H
              Nov 22 '18 at 7:06



















            • i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

              – S.H
              Nov 22 '18 at 7:06

















            i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

            – S.H
            Nov 22 '18 at 7:06





            i know how to do it its very simple i am doing it in many other apis ... but i am just confused about name="basics[last_name]" this basics

            – S.H
            Nov 22 '18 at 7:06


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424919%2fhow-to-post-data-in-an-array-in-android-using-retrofit-2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules