0

Ошибка

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 36 path $.data[0].object

@GET("?act=auth")
Call<AuthResponse> auth(@Query("login") String login, @Query("password") String password);

Вот Json:

{"data":[{"success":true,"object":{"id":"18","phone":"(444)444-4444","dop_phone":"(222)111-1111","email":"abaaaba@mail.kz","name":"beka","city":"turkestan","address":"mkrTGJ","user_type":"0"},"errors":""}]}


btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String number = eTxtUsername.getText().toString();
            String password = eTxtPassword.getText().toString();

            ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
            Call<AuthResponse> call =  apiInterface.auth(number,password);
            Log.i("ssss",""+call);
            if(call == null)
                Log.i("ssss",""+1);
            else
                Log.i("ssss",""+2);
            call.enqueue(new Callback<AuthResponse>() {
                @Override
                public void onResponse(Call<AuthResponse> call, Response<AuthResponse> response) {
                    Log.i("ssss",""+2322);

                @Override
                public void onFailure(Call<AuthResponse> call, Throwable t) {
                    Log.i("ssss",""+t);
                }
            });

        }
    });


  public class AuthResponse {

  @SerializedName("data")
  @Expose
  private List<DataAuth> data = new ArrayList<DataAuth>();

  @NonNull
  public List<DataAuth> getData() {
    return data;
  }

  public void setData(@NonNull List<DataAuth> data) {
    this.data = data;
  }
}


public class DataAuth {

@SerializedName("success")
@Expose
private boolean success;
@SerializedName("object")
@Expose
private List<InfoClient> infoClients = new ArrayList<InfoClient>();
@SerializedName("errors")
@Expose
private String errors;

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public List<InfoClient> getInfoClients() {
    return infoClients;
  }

  public void setInfoClients(List<InfoClient> infoClients) {
    this.infoClients = infoClients;
  }

  public String getErrors() {
    return errors;
  }

  public void setErrors(String errors) {
    this.errors = errors;
  }
}

public class InfoClient {

@SerializedName("id")
@Expose
private String id;
@SerializedName("phone")
@Expose
private String phone;
@SerializedName("dop_phone")
@Expose
private String dopPhone;
@SerializedName("email")
@Expose
private String email;
@SerializedName("name")
@Expose
private String name;
@SerializedName("city")
@Expose
private String city;
@SerializedName("address")
@Expose
private String address;
@SerializedName("user_type")
@Expose
private String userType;

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public String getDopPhone() {
    return dopPhone;
}

public void setDopPhone(String dopPhone) {
    this.dopPhone = dopPhone;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getUserType() {
    return userType;
  }

  public void setUserType(String userType) {
    this.userType = userType;
  }
}
4
  • Проблема в AuthResponse Покажите код этого класса.
    – temq
    11 ноя 2016 в 6:10
  • добавил код посмотрите
    – Mr.Baga
    11 ноя 2016 в 6:23
  • класс DataAuth покажите
    – Nikotin N
    11 ноя 2016 в 6:26
  • добавил код.....
    – Mr.Baga
    11 ноя 2016 в 6:32

1 ответ 1

0

В классе DataAuth поле private List<InfoClient> infoClients должно быть обычным объектом, т.е private InfoClient infoClients

2
  • Исправил но все равно выходит ошибка Expected BEGIN_OBJECT but was STRING at line 1 column 37 path $.data[0].object
    – Mr.Baga
    11 ноя 2016 в 6:39
  • @Mr.Baga сейчас структура классов должна полностью соответствовать JSON'у, посмотрите все ли вы правильно исправили и приложите обновленный код к вопросу.
    – temq
    11 ноя 2016 в 7:04

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.