-4
我是根據某些搜索條件查詢FlickR,並且響應是JSON數組。這裏是根級別與前兩個結果一起:如何訪問JSON數組中的子項目
{
photos: {
page: 1,
pages: 4222,
perpage: 100,
total: "422175",
photo: [
{
id: "28571356563",
owner: "[email protected]",secret: "c4ca6c4364",
server: "8050",
farm: 9,
title: "95040021.jpg",
ispublic: 1,
isfriend: 0,
isfamily: 0,
url_m: "https://farm9.staticflickr.com/8050/28571356563_c4ca6c4364.jpg",
height_m: "332",
width_m: "500"
},
{
id: "28571342883",
owner: "[email protected]",
secret: "db35a59412",
server: "8307",
farm: 9,
title: "Red #Sunset #Silhouette #Trees #Photography",
ispublic: 1,
isfriend: 0,
isfamily: 0,
url_m: "https://farm9.staticflickr.com/8307/28571342883_db35a59412.jpg",
height_m: "500",
width_m: "424"
},
當我加載的結果,我經歷的所有項目迭代(「總」數據),並加載到RecyclerView。
最終,我想遍歷「照片」,然後獲取每張照片的「url_m」。這是通過改造我的當前呼叫了Flickr API:
Call<List<Photo>> call = apiInterface.getImages(mQuery);
call.enqueue(new Callback<List<Photo>>() {
@Override
public void onResponse(Call<List<Photo>> call, Response<List<Photo>> response) {
}
@Override
public void onFailure(Call<List<Photo>> call, Throwable t) {
}
});
}
});
我怎麼會通過所有的照片進行迭代,並得到每張相片的網址是什麼?我爲每個模型類設置了完全映射到FlickR API JSON對象的模型類:
,那豈不是叫呢? –
tccpg288
你的第一個POJO應該解析'photos' JSONObject,POJO將包含'photos'對象列表 –
所以基於這個邏輯,如果我想訪問「total」項(假設我已經把我的JSON映射到Java ),我會輸入回調代碼? – tccpg288