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

如何解决在更新后的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","jon@gmail.com   ","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","reference_email@gmail.com");
        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());
        }
    });
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-