我使用改造 2.0.0 和 GSON 转换器。
我有响应字符串
{"errors":["Incorrect unlock code"]}
我尝试将其转换为对象:
public class User {
ArrayList<String> errors;
}
但在回调response.body()
中为空。对于其他不包含数组,只有字符串和 int 字段的对象,一切正常!
这就是我初始化改造的方式:
OkHttpClient client = new OkHttpClient();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
client.interceptors().add(interceptor);
retrofit = new Retrofit.Builder()
.baseUrl("http://testurl.com")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(SignApi.class);