I have the same question, I explain it with the basis of my own project, you should use my request for modification
@GET("StudentApi/getAll") Observable<List<Person>> getPersons();
and I have an interface to run a server request, and it has this method to run getPersons () and return a list of json array of face information
Observable<Person> getAllPersons();
, and the important part is the body up method, and it should look below
@Override public Observable<Person> getAllPersons() { Observable<List<Person>> observable = serviceGenerator.getService().getPersons(); return observable .flatMap(new Function<List<Person>, Observable<Person>>() { @Override public Observable<Person> apply(List<Person> persons) throws Exception { return Observable.fromIterable(persons); } }); }
I found that the fromIterable method returns json array objects one by one, and finally, in action, I get json objects from the methods at the top, for example, below.
public void getPersons(){ personsRepository.getAllPersons() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Person>() { @Override public void onNext(Person value) { Log.e("person info is",value.getpName() + value.getpFamily()); } @Override public void onError(Throwable throwable) { Log.e("onError",throwable.toString()); } @Override public void onComplete() { Log.e("onComplete","onComplete"); } }); }
I hope this is helpful :)
source share