我正在使用提供以下響應的API。 (爲簡單起見,我已將數據內的對象數量減少到2個)。JSON對象內部而不是陣列中的多個JSON對象
{
"Response": "Success",
"Message": "Coin list succesfully returned!",
"BaseImageUrl": "https://www.cryptocompare.com",
"BaseLinkUrl": "https://www.cryptocompare.com",
"Data": {
"42": {
"Id": "4321",
"Url": "/coins/42/overview",
"ImageUrl": "/media/19984/42.png",
"Name": "42",
"CoinName": "42 Coin",
"FullName": "42 Coin (42)",
"Algorithm": "Scrypt",
"ProofType": "PoW",
"FullyPremined": "0",
"TotalCoinSupply": "42",
"PreMinedValue": "N/A",
"TotalCoinsFreeFloat": "N/A",
"SortOrder": "34"
},
"365": {
"Id": "33639",
"Url": "/coins/365/overview",
"ImageUrl": "/media/352070/365.png",
"Name": "365",
"CoinName": "365Coin",
"FullName": "365Coin (365)",
"Algorithm": "X11",
"ProofType": "PoW/PoS",
"FullyPremined": "0",
"TotalCoinSupply": "2300000000",
"PreMinedValue": "N/A",
"TotalCoinsFreeFloat": "N/A",
"SortOrder": "916"
}
},
"Type": 100
}
我想將所有對象放在數據中的數組中,以便我可以將它們傳遞給我的RecyclerView的適配器。
我利用Retrofit2和RxJava2進行網絡操作。
這是我改裝製造商此刻的代碼:http://www.jsonschema2pojo.org/
我已編輯類數據,以便它包含:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
我使用也產生了POJO類硬幣和數據數組硬幣而不是單個對象:
public class Data {
@SerializedName("Coin")
@Expose
private Coin[] coins;
public Coin[] getCoin() {
return coins;
}
public void setCoins(Coin[] coins){}
}
我會如何去添加數據中的所有對象到Coin數組? 我是否需要創建自定義轉換器,如果是,我該如何實現?
在此先感謝!
這將如何解決獲取數組中的所有對象的問題? – DennisN