I am using Retrofit 2.0 in my application. Everything was fine, but when I started the request, it returns:
**java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING
at line 1 column 21 path $[0].iso**
Here is my API:
public interface GetPhones {
@GET("phones.php")
Call<ArrayList<Phones>> getPhones();
}
and model class:
public class Phones {
int id;
char[] iso;
String name;
String phone_1;
String phone_2;
String phone_3;
}
and the code in the fragment:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL_API)
.client(SSLSuppressClient.trustcert())
.addConverterFactory(GsonConverterFactory.create())
.build();
GetPhones getPhonesInfo = retrofit.create(GetPhones.class);
Call<GetPhones> call = getPhonesInfo.getPhones();
call.enqueue(new Callback<GetPhones>() {
@Override
public void onResponse(Response<GetPhones> response, Retrofit retrofit) {
Toast.makeText(getActivity(), "Success!", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getActivity(), "Failure!", Toast.LENGTH_SHORT).show();
Log.d("LOG", t.getMessage());
}
});
The problem seems to be aroung gzip, which is included on the server side. But when I try the code with Response - it works like a charm. So the problem is not gzipping.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL_API)
.client(SSLSuppressClient.trustcert())
.addConverterFactory(GsonConverterFactory.create())
.build();
GetPhones getPhonesInfo = retrofit.create(GetPhones.class);
Call<List<com.squareup.okhttp.Response>> call = getPhonesInfo.getPhones();
call.enqueue(new Callback<List<com.squareup.okhttp.Response>>() {
@Override
public void onResponse(Response response, Retrofit retrofit) {
Toast.makeText(getActivity(), "Success!", Toast.LENGTH_SHORT).show();
Log.d("LOG", response.message());
Log.d("LOG", response.raw().toString());
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getActivity(), "Failed!", Toast.LENGTH_SHORT).show();
Log.d("LOG", t.getMessage());
}
});
Where am I wrong?
source
share