0
I have the following return in json
{
"cardapio": [
{
"tipoprato": "SALADAS",
"pratos": [
{
"prato": "ALFACE + REPOLHO ROXO"
}
]
},
{
"tipoprato": "PRATO PRINCIPAL",
"pratos": [
{
"prato": "ESTROGONOFE DE GR?O DE BICO"
},
{
"prato": "GALETTE DE PVT, GLUTEN E QUEIJO MUCARELA"
}
]
},
{
"tipoprato": "ACOMPANHAMENTO",
"pratos": [
{
"prato": "FEIJ?O C/ MAXIXE, QUIABO E COUVE"
},
{
"prato": "ARROZ BRANCO"
},
{
"prato": "ARROZ INTEGRAL"
}
]
},
{
"tipoprato": "CALDOS",
"pratos": [
{
"prato": "CALDO DE COUVE - FLOR"
}
]
}
]
}
At first it would be two classes: Typoprate and Dishes.
My doubt is how I would bring this result to retrofit?
I’m new to retrofit.
It would take two classes?
class Cardapio{
private String tipo;
private Prato[] prato;
...
}
Dish class
class Prato{
private String prato;
}
My interface
GET("/restaurante/")
public void getCardapio(
Callback<List<Cardapio>> cardapioList;
);
Or it would be better to separate each thing, bring only the Types of Dishes then only the dishes?
My goal later is to make an expandable list
the way of calling the interface is right there my question?
– adventistaam
@adventistaam this way ai do not know if it works. I edited my question asking how it would be.
– viana
Wouldn’t need the getters and setters, no, it’s not?
– adventistaam
Need, for when you are going to assign the values at some other time. I thought you would already be aware of this. :-)
– viana
I get it. So it follows the pattern right?
– adventistaam
Just to redeem the value using retrofit does not need the get and set, but you will need them at some point from your code. I did not put it because you asked only assignments using retrofit. It follows yes the pattern.
– viana
Blz. Thanks! I’m starting at Retrofit.
– adventistaam
@adventistaam you came to use this way as I passed?! Give me a feedback on that answer. I saw that you asked another question, but first I wanted you to validate so that I can answer another question, which would be based on this or not. = D
– viana
I’m actually trying, as I’m studying, I still don’t know many things like: I’m using your suggestion but I’m not being able to visualize in Sponse because it would be a list and sublist.
public void onResponse(Call<List<Cardapio>> call, Response<List<Cardapio>> response) {
 List<Cardapio.Conteudo> cardapioResponse = response.body();
 //Percorre a lista e exbie o nome de cada respositório
 for( Conteudo cardapio : cardapioResponse ){
 Log.i("Cardapio", cardapio.getConteudo().toString() );
 }
 }
– adventistaam
Check out this article by Vogella. I think it will help a lot: http://www.vogella.com/tutorials/Retrofit/article.html
– viana
Blz. I’m giving him a study too. Thanks
– adventistaam