我有像这样的json回复
[{
"id": 94973,
"slug": "la-liga-real-betis-1-1-barcelona-29-januari-2017",
"title": {
"rendered": "La Liga: Real Betis 1-1 Barcelona 29 Januari 2017"
}
}, {
"id": 94957,
"slug": "fa-chelsea-4-0-brentford-28-januari-2017",
"title": {
"rendered": "FA: Chelsea 4-0 Brentford, 28 Januari 2017"
}
}, {
"id": 94944,
"slug": "serie-a-ac-milan-1-2-napoli-22-januari-2017",
"title": {
"rendered": "Serie A: AC Milan 1-2 Napoli, 22 Januari 2017"
}
}]
我想要做的是获取渲染标题的值而不是id和slug
这是我的改装课程
public void onResponse(Call<List<Coba>> call, Response<List<Coba>> response) {
try {
List<Coba> jsonResponse = response.body();
data= new ArrayList<>();
data.addAll(jsonResponse);
adapter = new MyAdapter(data);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
Log.i("HASIL", "onResponse: "+data);
}catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
}
如何使用retfrofit获取该值?
答案 0 :(得分:0)
创建一个类
public class CobaResponse {
Arraylist<Coba> cobas;
getCobas(){ return cobas; }
class Coba {
int id;
String slug;
Map<String,String> title;
getId(){ return id; }
getSlug(){ return slug; }
getMap(){ return title; }
}
}
在改造界面中使用该模型。
@Get("/requesturl")
Call<CobaResponse> getCobas();
最后onResponse方法。
Response.body().getCobas.get(0).getId();