I am trying to figure out how to parse JSON using Retrofit 2.1, and get an output array with Manager
objects
Created a request in the interface, in MainActivity
initialized Retrofit
itself
JSON file:
{ "managers": [ {"name": "John Smith", "plan": "100"}, {"name": "Alex Sprite", "plan": "96"}, {"name": "Den Bollom", "plan": "2"}, {"name": "Jaromir Jagr", "plan": "68"}, {"name": "Wane Gretzky", "plan": "99"}, {"name": "Winsent Trade", "plan": "54"}, {"name": "Paul Dagger", "plan": "30"}, {"name": "Tommy Gun", "plan": "60"}, {"name": "Luc Perry", "plan": "15"}, {"name": "Tend Smarr", "plan": "64"} ] }
ManagerApi
public interface ManagerAPI { String URL = "https://api.myjson.com/bins/"; @GET("xkyz.json") Call<Manager> getManagers(); }
Retrofit initialization method
private void requestData() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(ManagerAPI.URL) .addConverterFactory(JacksonConverterFactory.create()) .build(); ManagerAPI service = retrofit.create(ManagerAPI.class); }
There is also a class Manager
, with all the necessary hetero. I can not understand what to do next in this case.
service.getManagers();
? - JuriySPb ♦