我在登录上有麻烦。我从网上试了几个例子,但对我没什么用。
JSON
{
"responseCode":1,
"responseCodeText":"ok",
"response":
{
"id":1234,
"email":"test@test.cz",
"name":"name",
"lastname":"lastname",
"properties":[
//...
],
"rights":"admin",
"photo":"url",
"favorites":
[
//...
],
"token":"token"
}
}我已经从创建了类,所以应该可以。
接口
public interface LoginInterface {
@POST("login/{email}/{password}")
Call<UserResponse> login(@Path("email") String email, @Path("password") String password);
}调用活动
public void serviceInit() {
String email = edEmail.getText().toString();
String password = edPassword.getText().toString();
FactoryAPI.getInstanceLogin().login(email, password).enqueue(new Callback<UserResponse>() {
@Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if(response.isSuccessful()) {
Intent intent = new Intent(getContext(), AccountActivity.class);
startActivity(intent);
}
//TODO: load from sharedPreferences
}
@Override
public void onFailure(Call<UserResponse> call, Throwable t) {
Log.e("error", "points not loaded");
}
});
}错误,我有错误
responseCodeText:“属性错误”
我收到服务器的请求。我的电子邮件和密码在GET,而不是在邮政
谢谢你的帮助
发布于 2016-08-23 13:13:34
问题在于:
@FormUrlEncoded
@POST("login")
Call<UserResponse> login(@Field("email") String email, @Field("password") String password);发布于 2016-08-23 12:26:36
json将映射到的响应类必须具有与json相同的确切结构和属性。
因此,您的UserResponse应该包括all字段。就像这样:
public class UserResponseDTO {
public int responseCode;
public String responseCodeText;
public UserDTO response;
}
public class UserDTO {
public int id;
public String email;
public String name;
public String lastname;
public List<PropertyDTO> properties;
public String rights;
public String photo;
public List<FavoriteDTO> favorites;
public String token;
}https://stackoverflow.com/questions/39100498
复制相似问题