Answer the question
In order to leave comments, you need to log in
How to take nested object from response.body() for further work?
here is the json
BODY structure
{
"keyword": "Звездные",
"pagesCount": 15,
"searchFilms": [
{
"id": "714888",
"type": "KPFilm",
"nameRU": "Звёздные войны: Пробуждение силы",
"nameEN": "Star Wars: Episode VII - The Force Awakens",
"description": "США, Джей Джей Абрамс(фантастика)",
"posterURL": "film_iphone/iphone60_714888.jpg",
"filmLength": "2:16",
"year": "2015",
"country": "США",
"genre": "фантастика, фэнтези, боевик",
"rating": "7.3 (97 627)"
},
...
}
private void loadJSON(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.learn2crack.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
final RequestInterface request = retrofit.create(RequestInterface.class);
Call<JSONResponse> call = request.getJSON();
call.enqueue(new Callback<JSONResponse>() {
@Override
public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
Log.d(TAG, "response.body()");
JSONResponse jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getMuvi()));
Log.d(TAG, data.toString());
adapter = new DataAdapter(data);
recyclerView.setAdapter(adapter);
}
@Override
public void onFailure(Call<JSONResponse> call, Throwable t) {
Log.d("Error",t.getMessage());
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question