我正在为登录Api使用改造。我得到了空体成功的回应。 我尝试调试该应用并对其进行搜索,但是没有什么用,但是我没有弄清楚出什么问题了
这是我应该收到的回复
{ “标题”:{}, “原版的”: { “ACCESS_TOKEN”: “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8yMDkuOTcuMTM1LjIzOVwvYXBpXC9sb2dpbiIsImlhdCI6MTUzMTY3ODE1OSwiZXhwIjoxNTMxNjgxNzU5LCJuYmYiOjE1MzE2NzgxNTksImp0aSI6ImZHMXIyN1QwZVY0TldxMVAiLCJzdWIiOjQ0MSwicHJ2IjoiZTVjYjM4YmY4ZDIzZGQ2ZWE4ZWFiODIwZDk1NTVlNmI3NGU2NzU0ZSJ9.GeB2gqSKNf2ebq-Z-FkYg328aOUqYmkkBlL8rIBM9p0” “ token_type”:“承载者”, “ expires_in”:3600 }, “ exception”:null}
这是我的课堂模型
public class login_Resp {
@SerializedName("headers")
@Expose
private String headers;
@SerializedName("access_token")
@Expose
private String accessToken;
@SerializedName("token_type")
@Expose
private String tokenType;
@SerializedName("expires_in")
@Expose
private int expiresIn;
@SerializedName("exception")
@Expose
private Object exception;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
public String getHeaders() {
return headers;
}
public void setHeaders(String headers) {
this.headers = headers;
}
public Object getException() {
return exception;
}
public void setException(Object exception) {
this.exception = exception;
}
主要活动
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mobile = myidText.getText().toString();
String password=myPassword.getText().toString();
if(!TextUtils.isEmpty(mobile) &&
!TextUtils.isEmpty(password)) {
login(mobile, password);
}
}
});
}
private static String token;
private void login(String mobile ,String password);
Login login = new Login("store",mobile,password);
Api_Interface service =
Api_Client.getClient().create(Api_Interface.class);
// Call<String> call = service.storeLogin(login);
Call<login_Resp> call = service.storeLogin(login);
call.enqueue(new Callback<login_Resp>() {
@Override
public void onResponse(Call<login_Resp> call, Response<login_Resp> response) {
if(response.isSuccessful()) {
Log.i(TAG, "post submitted to API." + response.body());
token = response.body().getAccessToken();
}
else{
Log.i(TAG, "login is not correct." );}
}
@Override
public void onFailure(Call<login_Resp> call, Throwable t) {
Log.e(TAG, "Unable to submit post to API.");
}
});
答案 0 :(得分:0)
尝试一下:
public class LoginResponse
{
private Object headers;
private Object exception;
private Original original;
public Original getOriginal ()
{
return original;
}
public void setOriginal (Original original)
{
this.original = original;
}
public Object getHeaders() {
return headers;
}
public void setHeaders(Object headers) {
this.headers = headers;
}
public Object getException() {
return exception;
}
public void setException(Object exception) {
this.exception = exception;
}
}
public class Original
{
@SerializedName("access_token")
private String accessToken;
@SerializedName("token_type")
private String tokenType;
@SerializedName("expires_in")
private int expiresIn;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
}