我的异常为retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 10 path $.data
我要求数据为:
RestAdapter loginAdapter = Utils.buildAdapter();
final ApiConfig signUpApi = loginAdapter.create(ApiConfig.class);
signUpApi.signUp(new SignupDetailResponse.SignUpDetailRequestBody(email, password, AppConstants.DEVICE_TOKEN, AppConstants.DEVICE_TYPE),
new Callback<SignupDetailResponse.SignUpResponseBody>() {
@Override
public void success(SignupDetailResponse.SignUpResponseBody signUpDetailResponse, Response response) {
Long responseCode = signUpDetailResponse.responseCode;
Utils.SHOW_TOAST(context, responseCode.toString());
}
@Override
public void failure(RetrofitError retrofitError) {
if (retrofitError.getResponse() != null) {
Log.i(TAG, retrofitError.toString());
}
}
});
}
在Utils
,
public static RestAdapter buildAdapter() {
return new RestAdapter.Builder()
.setEndpoint(AppConfig.API_BASE_URL)
.build();
}
我的界面:
public interface ApiConfig {
@POST("/signUp")
public void signUp(@Body SignupDetailResponse.SignUpDetailRequestBody signUpDetailRequestBody, Callback<SignupDetailResponse.SignUpResponseBody> signUpDetailResponseCallback);
}
我的LoginResponse:
package com.shubham.network.response;
import com.google.gson.annotations.Expose;
public class SignupDetailResponse {
public static class SignUpDetailRequestBody {
final String email;
final String password;
final String acType;
final String deviceType;
public SignUpDetailRequestBody(String email, String password, String acType, String deviceType) {
this.email = email;
this.password = password;
this.acType = acType;
this.deviceType = deviceType;
}
}
public static class SignUpResponseBody {
@Expose
public String data;
@Expose
public Boolean success;
@Expose
public String message;
@Expose
public Long responseCode;
/**
* @return The data
*/
public String getData() {
return data;
}
/**
* @return The success
*/
public Boolean getSuccess() {
return success;
}
/**
* @return The message
*/
public String getMessage() {
return message;
}
/**
* @return The responseCode
*/
public Long getResponseCode() {
return responseCode;
}
}
}
预期的JSON响应:
{
"data": "1",
"success": true,
"message": "You have successfully SignUp. Please login to your registered email and activate your account",
"responseCode": 8
}
我想我已经正确地构建了我的模型。我还在我的项目中添加了retrofit(1.9.0)和gson(2.3.1)JARS。