在更新后的api android中发送多个数据类型参数

问题描述

我想在Retrofit.retrofit后期服务中发送具有不同数据类型的多个参数,但都无法正常工作,也不会给出错误代码

Api

    public class Api {
    private static Retrofit retrofit = null;
    public static ApiInterface getClient() {

    // change your base URL
    if (retrofit==null) {
        retrofit = new Retrofit.Builder()
                .baseUrl("https://ezyviewbooker.com/api/auth_v1/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //Creating object for our interface
    ApiInterface api = retrofit.create(ApiInterface.class);
    return api; // return the APIInterface object
}

}

我的界面代码ApiInterface:

public interface ApiInterface {

@FormUrlEncoded // annotation used in POST type requests
@POST("candidate_resume_upload_store")
    // API's endpoints
Call<Void> registration(@Field("category_id") String category_id,@Field("full_name") String full_name,@Field("country") String country,@Field("address") String address,@Field("personal_question_id") ArrayList<String> personal_question_id,@Field("personal_answer_id") ArrayList<String> personal_answer_id,@Field("competencies_skills") ArrayList<String> 
                               competencies_skills,@Field("work_responsibilities") ArrayList<String> 
                                  work_responsibilities,@Field("interest_hobbies") ArrayList<String> 
                                  interest_hobbies,@Field("societies") ArrayList<String> societies,@Field("reference_name") String reference_name,@Field("reference_position") String reference_position,@Field("reference_email") String reference_email,@Field("reference_number") String reference_number,@Field("token") String token,@Field("city") String city);





   }

主要活动家庭活动:

  public class Home extends AppCompatActivity {

ArrayList<String> interest;
ArrayList<String> question;
ArrayList<String> answers;
ArrayList<String> skills;
ArrayList<String> resposnsibilties;
ArrayList<String> socities;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    interest=new ArrayList<String>();
    question=new ArrayList<String>();
    answers=new ArrayList<String>();
    skills=new ArrayList<String>();
    resposnsibilties=new ArrayList<String>();
    socities=new ArrayList<String>();

    socities.add("IPSC");
    socities.add("IPSC_@");

    interest.add("IPSC");
    interest.add("IPSC_@");

    question.add("11");
    question.add("20");
    question.add("21");
    question.add("22");
    answers.add("9");
    answers.add("10");

    resposnsibilties.add("app developing");
    resposnsibilties.add("Team work");

    skills.add("Swift");
    skills.add("JAVA");
    signUp();
}
private void signUp() {
    // display a progress dialog
    final ProgressDialog progressDialog = new ProgressDialog(Home.this);
    progressDialog.setCancelable(false); // set cancelable to false
    progressDialog.setMessage("Please Wait"); // set message
    progressDialog.show(); // show progress dialog



    (Api.getClient().registration("1","Khan","pakistan","Baheria town",question,answers,skills,resposnsibilties,interest,socities,"Jon","Senior Graphic Designer","[email protected]   ","09009456788","eyJ","karachi")).enqueue(new Callback<Void>() {
        @Override
        public void onResponse(Call<Void> call,Response<Void> response) {


            progressDialog.dismiss();

        }

        @Override
        public void onFailure(Call<Void> call,Throwable t) {
            Log.d("response",t.getStackTrace().toString());
            Toast.makeText(Home.this,t.getStackTrace().toString(),Toast.LENGTH_LONG).show();
            progressDialog.dismiss();

        }
    });
}
 }

有五个arraylist,例如:兴趣,社交等,我想与其他String(如姓名地址等)一起发送

解决方法

尝试此代码-

public class ApiUtils {

    public static Retrofit getClient() {

        Retrofit retrofit = null;
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).connectTimeout(60,TimeUnit.SECONDS)
                .readTimeout(60,TimeUnit.SECONDS)
                .writeTimeout(60,TimeUnit.SECONDS).build();

        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl("https://ezyviewbooker.com/api/auth_v1/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }

}
,
 @POST("candidate_resume_upload_store")
  Call<SignUpResponse> savecv(@Body JsonObject registrationData);


 private static JsonObject generateRegistrationRequest() {
    JSONObject jsonObject = new JSONObject();
    try {
        JSONArray answerJsonObject_1 = new JSONArray();
        JSONArray questionJsonObject_1 = new JSONArray();
        JSONArray competencies_skillsJsonObject_1 = new JSONArray();
        JSONArray societiessubJsonObject_1 = new JSONArray();
        JSONArray interest_hobbiessubJsonObject_1 = new JSONArray();
        JSONArray work_responsibilitiessubJsonObject_1 = new JSONArray();


        answerJsonObject_1.put("105");
        answerJsonObject_1.put("107");
        questionJsonObject_1.put("85");
        questionJsonObject_1.put("86");
        competencies_skillsJsonObject_1.put("Swift_1_3");
        competencies_skillsJsonObject_1.put("JAVA_1_1_3");
        societiessubJsonObject_1.put("SC_1");
        societiessubJsonObject_1.put("IP");
        interest_hobbiessubJsonObject_1.put("hyking_1");
        interest_hobbiessubJsonObject_1.put("tracking_1");
        work_responsibilitiessubJsonObject_1.put("Team work");
        work_responsibilitiessubJsonObject_1.put("Time Management");



        jsonObject.put("category_id",6);
        jsonObject.put("full_name","UMair Khan Ali");
        jsonObject.put("country","Pakistan");
        jsonObject.put("city","Karachi");
        jsonObject.put("token","eyJ0eXoiaHR0cHM6Ly9lenl2aWV3YXBwLmNvbS90YXBpdHByb19hcGkvYXBpL2F1dGhfdjEvbG9naW4iLCJpYXQiOjE1OTc4MzI2NTEsImV4cCI6MTU5OTA0MjI1MSwibmJmIjoxNTk3ODMyNjUxLCJqdGkiOiJZamY2Z0tjVnU1MVppcGlUIn0.Mmp9Ys0rMIAOZ8fGOyLbI8SCOihVE3DNRenm6imu4Zk");
        jsonObject.put("reference_number","07733217379");
        jsonObject.put("reference_email","[email protected]");
        jsonObject.put("reference_position","Senior IT Developer");
        jsonObject.put("reference_name","Shoaib Khan");
        jsonObject.put("address","DHA PHASE 12");
        jsonObject.put("personal_question_id",questionJsonObject_1);
        jsonObject.put("personal_answer_id",answerJsonObject_1);
        jsonObject.put("competencies_skills",competencies_skillsJsonObject_1);
        jsonObject.put("interest_hobbies",interest_hobbiessubJsonObject_1);
        jsonObject.put("societies",societiessubJsonObject_1);
        jsonObject.put("work_responsibilities",work_responsibilitiessubJsonObject_1);
        Log.i("cccccc","dsadasdasds_111" + jsonObject);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    JsonParser jsonParser = new JsonParser();
    JsonObject gsonObject = (JsonObject) 
    jsonParser.parse(jsonObject.toString());
    return gsonObject;
}


   public void sendPost() {



    mAPIService.savecv(generateRegistrationRequest()).enqueue(new 
    Callback<SignUpResponse>() {
        @Override
        public void onResponse(Call<SignUpResponse> call,Response<SignUpResponse> response) {


            if(response.isSuccessful()) {
                showResponse(response.body().toString());
                Log.i("cccccc","dsadasdasds" + 
                response.body().getMessage().toString());
            }
        }

        @Override
        public void onFailure(Call<SignUpResponse> call,Throwable t) {
            Log.e("post submitted to API.",t.getLocalizedMessage());
        }
    });
}