gpt4 book ai didi

java - Android如何使用retrofit传递模态类和参数数组

转载 作者:行者123 更新时间:2023-12-02 02:46:00 32 4
gpt4 key购买 nike

//这里是模态类的数据

busi_data[otp_verified]: 
busi_data[pan]:
busi_data[gstin]:
busi_data[doc]: pan
busi_data[business_name]:
busi_data[entity_type]:
busi_data[mobile]:
busi_data[customer_email]:
busi_data[mode]:
busi_data[ses_email]:
busi_data[pluskey]:
busi_data[otp_auth]:
busi_data[otp]:
operation:

我正在使用retrofit向服务器发送数据。我想传递一个模态类作为参数。请帮忙解决。

最佳答案

您好,您可以使用下面的代码在 api 中传递模型类

@POST(Constants.ApiMethods.GET_LOGIN)
Flowable<GenericModel<LoginResponse>> doLogin(@Body RequestBody requestBody);


Flowable<GenericModel<LoginResponse>> getusers = mRestApis.doLogin(Utility.getRequest(HobbsRepairApp.getGsonWithExpose().toJson(LoginRequest)));
getusers.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.onErrorReturn(throwable -> {
String message = ((HttpException) throwable).response().errorBody().string();
GenericModel<LoginResponse> userBaseResponse = HobbsRepairApp.getGsonWithExpose().fromJson(message, GenericModel.class);
return userBaseResponse; })
.subscribe(responsData -> {
if (responsData != null) {
GenericModel<LoginResponse> responseGenericModel = responsData;
if ((responseGenericModel.getStatus() == 200) && (responseGenericModel.getResponse() != null)) {
LoginResponse loginResponse = responseGenericModel.getResponseModel(LoginResponse.class);
loginResponse.setMessage(responseGenericModel.getMessage());
mEventBus.post(loginResponse);
} else {
mEventBus.post(new APIError(105, responseGenericModel.getMessage()));
}
}
});


public static RequestBody getRequest(String reqString) {
MediaType mediaType = MediaType.parse("application/json");
return RequestBody.create(mediaType, reqString);
}

public static Gson getGsonWithExpose() {
if (mGson != null) {
mGson = null;
}
mGson = new GsonBuilder().setLenient().excludeFieldsWithoutExposeAnnotation().create();
return mGson;
}

关于java - Android如何使用retrofit传递模态类和参数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57144333/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com