发生错误预期为BEGIN_ARRAY,但在第1行第2列路径$处为BEGIN_OBJECT

时间:2019-02-26 17:30:13

标签: android retrofit rx-java rx-android

我是RxANdroid和Retrofit的新手,并遇到以下错误:

预期BEGIN_ARRAY,但在第1行第2列路径$ BEGIN_OBJECT中

我的活动中包含以下代码:

 disposable.add(apiService.getIncidents(1, "true")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableObserver<IncidentResponse>() {
                    @Override
                    public void onNext(IncidentResponse response) {
                        mResponse = response;
                        mIncidentAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(TAG, "onError: " + e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                })

我的ApiService如下所示:

public interface ApiService {

    @GET("api/now/v1/table/incident")
    Observable<IncidentResponse> getIncidents(@Query("priority") int priority, @Query("active") String active);
}

IncidentResponse如下所示:

public class IncidentResponse {
    @SerializedName("result")
    private List<Incident> incidents;

    public IncidentResponse() {

    }
    public IncidentResponse(List<Incident> incidents) {
        this.incidents = incidents;
    }

    public List<Incident> getIncidents() {
        return incidents;
    }

    public void setIncidents(List<Incident> incidents) {
        this.incidents = incidents;
    }
}

1 个答案:

答案 0 :(得分:0)

该错误告诉您期望的数组实际上是一个对象。虽然您没有显示json的样子,但是可以肯定地认为是由于private List<Incident> incidents;再试一次,然后使用private Incident incident;