Retrofit 2.2 传递数组参数

xiaoxiao2021-02-28  61

最近使用Retrofit2.2.0 传递数组参数,发现网络上找到的很多方式都不行,然后只好自己填坑,后台PHP需要客户端提交的是数组,但是给的接口文档如下:

请求地址:HOST/tools-config

HTTP方法:POST

请求参数:

参数类型必填示例说明idListlist是[‘1’, ‘3’, ‘2’]配置可见应用id列表

参数说明:

+idList是已添加应用id数组,按自定义排序传递

返回实例:

{ "errcode":200, "errmsg":"ok" }

直接上代码:

@FormUrlEncoded @POST("matter/app-config") Flowable<JsonResponse> toolsConfig(@Field("idList[]") List<String> idList);

使用

//mToolIdList 是一个集合。 Retrofits.getApi().toolsConfig(mToolIdList) .compose(this.<JsonResponse>bindToLifecycle()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<JsonResponse>() { @Override public void accept(@NonNull JsonResponse jsonResponse) { // do something } });
转载请注明原文地址: https://www.6miu.com/read-79142.html

最新回复(0)