【发布时间】:2019-09-24 10:35:52
【问题描述】:
我的目标或目标是提出这样的请求以使其成功:
现在我的当前代码如下所示:
WebApi client = ServiceGenerator.createService(WebApi.class);
final Call<BaseResponse<BookingInfoEntity>> call = client.startBooking(
WebUtilities.createPartFromString(SharePreferences.getUserId(context)),
WebUtilities.createPartFromString(""), //trainer_id
WebUtilities.createPartFromString(String.valueOf(listener.getTrainerTypesObject().get(0))), //train type
WebUtilities.createPartFromString(String.valueOf(hours)),
WebUtilities.createPartFromString(String.valueOf(payment_id)),
WebUtilities.createPartFromString(SharePreferences.getCityId(context)),
WebUtilities.createPartFromString(listener.getSelectedDate()));
}
public static RequestBody createPartFromString(String descriptionString) {
return RequestBody.create(okhttp3.MultipartBody.FORM, descriptionString);
}
@Multipart
@POST(START_BOOKING)
Call<BaseResponse<BookingInfoEntity>> startBooking(@Part("trainee_id") RequestBody trainee_id,
@Part("trainer_id") RequestBody trainer_id,
@Part("trainer_types[][trainer_type_id]")RequestBody train_type,
@Part("number_of_hours") RequestBody number_of_hours,
@Part("payment_type_id") RequestBody payment_type_id,
@Part("city_id") RequestBody city_id,
@Part("meeting_date") RequestBody meeting_date);
我的问题是:如何动态插入
trainer_types[][trainer_type_id],
当我有 5 个培训师类型 ID 时,我想要, 我如何在他们的键中插入一个 5 trainer_type_id 并用它设置一个值?
我只是想复制上面的图像,以便我可以正确解决这个值。
【问题讨论】:
-
你可以传递多个 id 用逗号分隔的字符串
-
你是什么意思?
-
你可以将 trainer_types 像 1,2,3,4 作为字符串传入
-
不,我不能。要求是每个数组只传递一个值;我需要像这样传递它:“trainer_types”:[ {“trainer_type_id”:1},{“trainer_type_id”:2},{“trainer_type_id”:3}]
标签: android retrofit postman multipartform-data multipart