java - How to parse RxJava to receive just the data that i want? -


i want numbers, i'm receiving @ log:

[boletim(grade=4.5), boletim(grade=9.5)]

the response:

public class graderesponse {      @inject     retrofit retrofit;      @inject     mainpresenter mainpresenter;      public void getgraderx() {          myapplication.getmaincomponent().injectintograderesponse(this);// informando ao dagger sobre o uso de um component e necessidade de injetar dependĂȘncia          subscription getgrade = retrofit                 .create(gradeservice.class)                 .getgrade()                 .subscribeon(schedulers.newthread())                 .observeon(androidschedulers.mainthread())                 .map(model -> {                      return model.getboletim();                  })                 .subscribe(new observer<boletim[]>() {                     @override                     public void oncompleted() {                      }                      @override                     public void onerror(throwable e) {                         log.i(tag, "saporra vai me matar ainda");                     }                      @override                     public void onnext(boletim[] grades) {                         log.i(tag, arrays.aslist(grades).tostring());                     }                 });     } } 

the models:

grademodel:

@serializedname("boletim")     @expose     private boletim[] boletim; 

boletim.class

public class boletim {      @serializedname("grade")     @expose     private double grade; 

the retrofit service ok, dependency injection working. i'm receiving onsuccess method rxjava, need receiving numbers without "[boletim(grade=".

you seeing tostring of objects because entire object in map!

only numbers without "[boletim(grade=".

way can't map again , extract it?

.map(model -> {               // map returns boletim[]      return model.getboletim();  }) .map(boletim -> {             // map returns double[]     double grades = new double[boletim.length];     (int =0; < grades.length ; i++) {         grades[i] = boletim[i].getgrade() ;     }      return grades; }).subscribe(new observer<double[]>() {   // subscribes double[]     @override     public void oncompleted() {      }      @override     public void onerror(throwable e) {         log.i(tag, "saporra vai me matar ainda");     }      @override     public void onnext(double[] grades) {         log.i(tag, arrays.tostring(grades));     } } 

or put loop onnext

if don't want observable of arrays, use flatmap


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -