-1

When I am parsing JSON response using Retrofit, I am getting the below error:

Expected BEGIN_ARRAY but was BEGIN_OBJECT

My JSON response is :

{"Hints":"Within past week?,Within past month?,Within past year?,2000s?,1990s?,1980s?,1970s?,1960s?,Natural disaster?,Political?,Sports-related?,Movies-related?,Music-related?,Technology/Science?,Headline News?,International News?,Regional/Local News?"}

And Model Class:

public class User {

    String Hints;

    public String getHints() {
        return Hints;
    }

    public void setHints(String Hints) {
        this.Hints = Hints;
    }

    public User() {
    }

    public User(String Hints) {
        this.Hints = Hints;
    }
}

And the Interface is :

public interface UserService {
    @GET("/getCategoryHints/3")
    void getUser(Callback<List<User>> callback);
}

Please let me know the possible cause for this error.

Harry
  • 87,580
  • 25
  • 202
  • 214
SHOBHAN
  • 51
  • 8
  • Error clearly saying it should start with array `[` but it starting with object `{`. I dont know why is it so. But guessing on error type. – Shabbir Dhangot Jul 29 '15 at 05:41
  • You have `List` Your json is not array of objects. – Raghunandan Jul 29 '15 at 05:42
  • see this answer related your Error http://stackoverflow.com/questions/9598707/gson-throwing-expected-begin-object-but-was-begin-array and http://stackoverflow.com/questions/10073290/expected-begin-array-but-was-begin-object-with-an-array-of-three-elements – Shabbir Dhangot Jul 29 '15 at 05:44
  • I have highlighted the error message, removed extra line breaks from the code block. I have also removed client name from title because it is not required due to presence of tags. – Harry Jul 29 '15 at 06:01

1 Answers1

0

Try this using GSON,

public class User {

@Expose
private String Hints;

/**
* 
* @return
* The Hints
*/
public String getHints() {
return Hints;
}

/**
* 
* @param Hints
* The Hints
*/
public void setHints(String Hints) {
this.Hints = Hints;
}

} 

and remove the List<User> as your response isn't a JSON array

public interface UserService {
    @GET("/getCategoryHints/3")
    void getUser(Callback<User> callback);
}
Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50