gpt4 book ai didi

java - 带有响应类名称的 Android Retrofit 2 发布请求响应

转载 作者:搜寻专家 更新时间:2023-11-01 08:24:01 24 4
gpt4 key购买 nike

在我的应用程序中,我在正文中使用特殊代码向服务器发出发布请求。然后我应该在响应中获得一些信息。但是,我总是得到响应类的名称。
我的请求码:

@POST("/accounts/login/vk-oauth2/")
Call<RegistrationProcessCodeResponse> postCode(@Body CodePostRequest code);

我的响应类:

public class RegistrationProcessCodeResponse {
private String message;
private String partial_token;
private String phase;

public String getMessage() {
return message;
}

public String getPartial_token() {
return partial_token;
}

public String getPhase() {
return phase;
}

public void setMessage(String message) {
this.message = message;
}

public void setPartial_token(String partial_token) {
this.partial_token = partial_token;
}

public void setPhase(String phase) {
this.phase = phase;
}
}

我的请求代码:

HseAlumniApi hseAlumniApi = HseAlumniApi.retrofit.create(HseAlumniApi.class);
Call<RegistrationProcessCodeResponse> postComment = hseAlumniApi.postCode(codePostRequest);
postComment.enqueue(new Callback<RegistrationProcessCodeResponse>() {
@Override
public void onResponse(Call<RegistrationProcessCodeResponse> call, Response<RegistrationProcessCodeResponse> response) {
Log.d("myLogs", "String.valueOf(response.code())\n" + String.valueOf(response.code()));
Log.d("myLogs", "response.body().toString()\n" + response.body().toString());
if (response.isSuccessful()) {
Log.d("myLogs", "Request succeeded");
}
}

@Override
public void onFailure(Call<RegistrationProcessCodeResponse> call, Throwable t) {
Log.d("myLogs", "Request failed");
}
});

我的日志:

D/myLogs: String.valueOf(response.code())
200
D/myLogs: response.body().toString()
com.example.vitaly.hsealumni.RegistrationProcessCodeResponse@498e7e7
D/myLogs: Request succeeded

响应JSON:

{
"message": "email needed",
"partial_token": "231445d4fc5a4ed99dccb681942d5d7e",
"phase": 1
}

我真的不知道该怎么办,请帮忙

最佳答案

public class RegistrationProcessCodeResponse {
private String message;
private String partial_token;
private String phase;

public RegistrationProcessCodeResponse() {
message = "";
partial_token = "";
phase = "";
}

// getters and setters

@Override
public String toString() {
return "RegistrationProcessCodeResponse{" +
"message='" + message + '\'' +
", partial_token='" + partial_token + '\'' +
", phase='" + phase + '\'' +
'}';
}
}

关于java - 带有响应类名称的 Android Retrofit 2 发布请求响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224922/

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