Hello, how are you?
I would like your help to be able to convert a JsonArray to ArrayList < > on android.
I make a request that returns the following Json:
{"normal":{"test_graph":{"VALORES (R$)":"valor"},"randons":[],"id":"","valueField":null,"titleField":null,"dataProvider":[{"category":"Entrada","valor":30.00},{"category":"Comissão cambista","valor":3.00},{"category":"Total","valor":27.00}],"colors":["#002240"],"itpArrayBlue":["#002240","#0059A8","#639CFF","#76C1ED","#9AA9AD","#001323","#00498A","#8DB7FF","#619EC2","#8C9A9E","#5C768B","#8BACC9","#B8D2FF","#C5DBE8","#CAD1D2"],"itpArrayGreen":["#46CC3D","#279300","#28682B","#344F2D","#87AD87"],"graph":[{"title":"VALORES (R$)","value":"valor","lineColor":"#002240","column":true}],"oneColumn":null,"valueTime":null,"category":null,"valueAxes":[],"especial":false},"aovivo":{"test_graph":{"VALORES (R$)":"valor"},"randons":[],"id":"","valueField":null,"titleField":null,"dataProvider":[{"category":"Total","valor":0.0}],"colors":["#002240"],"itpArrayBlue":["#002240","#0059A8","#639CFF","#76C1ED","#9AA9AD","#001323","#00498A","#8DB7FF","#619EC2","#8C9A9E","#5C768B","#8BACC9","#B8D2FF","#C5DBE8","#CAD1D2"],"itpArrayGreen":["#46CC3D","#279300","#28682B","#344F2D","#87AD87"],"graph":[{"title":"VALORES (R$)","value":"valor","lineColor":"#002240","column":true}],"oneColumn":null,"valueTime":null,"category":null,"valueAxes":[],"especial":false}}v
I've created the Models:
AuxData
public class AuxData {
public JsonObject normal;
public JsonObject aovivo;
public ArrayList<DataProvider> dataProvider;
public AuxData(){
normal = new JsonObject();
aovivo = new JsonObject();
dataProvider = new ArrayList<DataProvider>();
}
}
DataProvider
public class DataProvider {
public String category;
public double valor;
}
Response
private Callback<AuxData> getCaixa() {
return new Callback<AuxData>() {
@Override
public void onResponse(Call<AuxData> call, Response<AuxData> response) {
switch (response.code())
{
case 200:{
JsonObject object = response.body().normal;
JsonArray array = new JsonArray();
array = object.get("dataProvider").getAsJsonArray();
ArrayList<DataProvider> dataa = new ArrayList<DataProvider>();
break;
}
case 400:{
Toasty.error(caixadata.this, "Erro", Toast.LENGTH_LONG, true).show();
break;
}
}
}
@Override
public void onFailure(Call<AuxData> call, Throwable t) {
Toasty.error(caixadata.this, "Erro", Toast.LENGTH_LONG, true).show();
}
};
}
How do I get data from this array and save it to an ArrayList? Or convert JsonArray to ArrayList.
Thank you!