Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY

I’m fairly new to JSON parsing , I’m using the Retrofit library of Square and ran into this problem.

I’m trying to parse this JSON reponse:

  • Setting up Android support package v7 for eclipse - GridLayout
  • What is the new generated code “This was auto-generated to implement the App Indexing API.”?
  • Make webview in a tablet simulate a small device
  • unable to implement descriptors in android
  • Volley JsonObjectRequest Post request not working
  • Apache HTTP Client Removal from API23, will that have an effect on Volley?
  • [
            "id": 3,
            "username": "jezer",
            "regid": "oiqwueoiwqueoiwqueoiwq",
            "url": "http:\/\/\/users\/3.json"
            "id": 4,
            "username": "emulator",
            "regid": "qwoiuewqoiueoiwqueoq",
            "url": "http:\/\/\/users\/4.json"
            "id": 7,
            "username": "test",
            "regid": "ksadqowueqiaksj",
            "url": "http:\/\/\/users\/7.json"

    Here are my models:

    public class Contacts {
        public List<User> contacts;

    public class User {
        String username;
        String regid;
        public String toString(){

    my Interface:

    public interface ContactsInterface {
        void contacts(Callback<Contacts> cb);

    my success method:

    public void success(Contacts c, Response r) {
        List<String> names = new ArrayList<String>();
        for (int i = 0; i < c.contacts.size(); i++) {
            String name = c.contacts.get(i).toString();
            Log.d("Names", "" + name);
        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, names);

    When I use it on my success method it throws the error

    Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column2

    What is wrong here?

  • android: turn off screen when close to face
  • How do I remove extra space above and below imageView?
  • How do I set a different color for the pressed state of the button?
  • Could not determine the dependencies of task ':app:crashlyticsStoreDeobsDebug' if I enable the proguard
  • What size of screenshot should I use in the Android Market?
  • Loading kernel module in Android kernel
  • 4 Solutions collect form web for “Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY”

    Right now you are parsing the response as if it was formatted like this:

      "contacts": [
        { .. }

    The exception tells you this in that you are expecting an object at the root but the real data is actually an array. This means you need to change the type to be an array.

    The easiest way is to just use a list as the direct type in the callback:

    void contacts(Callback<List<User>> cb);

    in your interface

    void contacts(Callback<Contacts> cb);

    By this code

    void contacts(Callback<List<Contacts>> cb);

    Convert it into a list.

    Below is the example:

    BenchmarksListModel_v1[] benchmarksListModel = res.getBody().as(BenchmarksListModel_v1[].class);

    Source Code Working

    public interface ApiInterface {
        Call<List<Message>> getInbox();
     call.enqueue(new Callback<List<Message>>() {
                public void onResponse(Call<List<Message>> call, Response<List<Message>> response) {
                public void onFailure(Call<List<Message>> call, Throwable t) {
                    Toast.makeText(getApplicationContext(), "Unable to fetch json: " + t.getMessage(), Toast.LENGTH_LONG).show();
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.