我正在使用Retrofit2,我需要调用API以获得信息。 API提供给我的JSON具有动态字段,这些字段根据参数值而变化。 请注意,我可以有任意数量的参数。以下是参数“ 1”,“ 2”的JSON。
{
"data":{
"1":{
"logo":"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
"id":1,
"name":"Bitcoin",
"symbol":"BTC",
"description":"Bitcoin (BTC) is...",
"date_added":"2013-04-28T00:00:00.000Z",
"platform":null,
"category":"coin"
}
},
"2":{
"logo":"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
"id":1,
"name":"Bitcoin",
"symbol":"BTC",
"description":"Bitcoin (BTC) is...",
"date_added":"2013-04-28T00:00:00.000Z",
"platform":null,
"category":"coin"
}
}
我已经创建了一个接口,在该接口中获取标头和参数键,然后在稍后进行改造时调用以返回我所需的信息。
public interface CurrencyService {
@GET(ApiConstants.CRYPTOCURRENCYINFO)
Call<CurrencyService> getCurrencyById(@Header("X-CMC_PRO_API_KEY")
String appkey,
@Query("id") int[] ints);
}
答案 0 :(得分:0)
public class CurrencyService {
Map<String, Data> data;
}
public class Data {
String logo;
int id;
String name;
String symbol;
String description;
String date_added;
Object platform;
String category;
}
Call<CurrencyService> getCurrencyById(@Header("X-CMC_PRO_API_KEY")String appkey, @Query("id") int[] ints);