【发布时间】:2022-01-04 08:35:52
【问题描述】:
我正在使用改造在 android 中制作登录功能。我已经为登录验证创建了一个端点,然后我使用 Postman 使用 raw (json) 对其进行了测试,并且它工作正常。但是当我使用改造将端点输入到 android 中时,我收到如下错误消息:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: 应为字符串,但在第 1 行第 39 列路径 $.message 处为 BEGIN_OBJECT
谁能帮帮我?
这里是我的来源:
ApiClient
public class ApiClient {
public static final String BASE_URL = "";
public static Retrofit retrofit;
public static Retrofit getRetrofit() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
AuthInterface
public interface AuthInterface {
@Headers("Content-Type: application/json")
@POST("auth/login")
Call<AuthPost> authPostCall(@Body String body);
}
AuthPost
public class AuthPost {
@SerializedName("status")
private String status;
@SerializedName("error_code")
private int error_code;
@SerializedName("message")
private String message;
@SerializedName("token")
private String token;
...getter and setter
}
登录活动
JSONObject payload = new JSONObject();
try {
payload.put("login_username", loginUsernameText);
payload.put("login_password", loginPasswordText);
} catch (JSONException e) {
e.printStackTrace();
}
Call<AuthPost> authPostCall = authInterface.authPostCall(payload.toString());
authPostCall.enqueue(new Callback<AuthPost>() {
@Override
public void onResponse(Call<AuthPost> call, Response<AuthPost> response) {
if (response.code() == 200) {
} else {
}
}
@Override
public void onFailure(Call<AuthPost> call, Throwable t) {
t.printStackTrace();
}
});
【问题讨论】:
-
错误是不言自明的......你不明白什么?