George Santos George Santos - 5 months ago 38
Android Question

Android Retrofit

I'm trying to read a Json using Retrofit library , however when I try to make the request get the following message : java.lang.IllegalStateException : Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 $ path

How can I fix this?


This is the most probable cause of your problem. You expect your backend to return a list of objects thus this code:

Call<List<Character>> call

, but what you should do is to create a model class because in your JSON list of characters maybe be named somehow for example "my_characters". If so, your model should be like this:

class Characters {
    List<Character> my_characters;

If that's the problem then you should use this model instead of List<Character>