How to make a list from a request GET in Retrofit 2? [closed]

0

My question is how do I get the JSON of the request and put it in an ArrayList so that I can inflate the RecyclerView. Thanks in advance.

    
asked by anonymous 12.12.2017 / 05:17

2 answers

1

Adds a CoverterFactory to the instantiation of Retrofit , via addConverterFactory , and in case JSON returns an Array, you can easily map it to an ArrayList.

    
12.12.2017 / 14:44
0

You can convert your JSON into a JsonObject and go capturing its attributes.

JSON

    {
     "nome": "José da Silva"
     "idade" : 30
     }

JAVA

JSONObject jsonObj= new JSONObject("seu json aqui");
String nome = jsonObj.getString("nome");
int idade = jsonObj.getInt("idade");

Exit

Log.d("App", "Nome: " + nome);//José da Silva
Log.d("App", "Idade: " + idade);//30

Reference: link

Another alternative would be the GSON library, in which you directly convert an Object to Json and a Json to Object. Link: link

    
12.12.2017 / 10:56