Пытаюсь обработать JSON ответ, необходимо выделить "data" (Использую CoinMarketCap)
{
"status": {
"timestamp": "2019-03-04T11:51:50.249Z",
"error_code": 0,
"error_message": null,
"elapsed": 5,
"credit_count": 1
},
"data": [
{
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"slug": "bitcoin",
"circulating_supply": 17570250,
"total_supply": 17570250,
"max_supply": 21000000,
"date_added": "2013-04-28T00:00:00.000Z",
"num_market_pairs": 6722,
"tags": [
"mineable"
],
"platform": null,
"cmc_rank": 1,
"last_updated": "2019-03-04T11:51:23.000Z",
"quote": {
"USD": {
"price": 3761.08116396,
"volume_24h": 8472364962.15305,
"percent_change_1h": 0.463327,
"percent_change_24h": -2.66362,
"percent_change_7d": -2.18666,
"market_cap": 66083136321.06819,
"last_updated": "2019-03-04T11:51:23.000Z"
}
}
},
{
"id": 1027,
"name": "Ethereum",
"symbol": "ETH",
"slug": "ethereum",
"circulating_supply": 105119454.4991,
"total_supply": 105119454.4991,
"max_supply": null,
"date_added": "2015-08-07T00:00:00.000Z",
"num_market_pairs": 4766,
"tags": [
"mineable"
],
"platform": null,
"cmc_rank": 2,
"last_updated": "2019-03-04T11:51:19.000Z",
"quote": {
"USD": {
"price": 127.789942421,
"volume_24h": 3989111074.78033,
"percent_change_1h": 1.32918,
"percent_change_24h": -5.41225,
"percent_change_7d": -8.35691,
"market_cap": 13433209037.766918,
"last_updated": "2019-03-04T11:51:19.000Z"
}
}
},
{
"id": 52,
"name": "XRP",
"symbol": "XRP",
"slug": "ripple",
"circulating_supply": 41432141931,
"total_supply": 99991683860,
"max_supply": 100000000000,
"date_added": "2013-08-04T00:00:00.000Z",
"num_market_pairs": 332,
"tags": [],
"platform": null,
"cmc_rank": 3,
"last_updated": "2019-03-04T11:51:04.000Z",
"quote": {
"USD": {
"price": 0.305550941952,
"volume_24h": 663669735.085875,
"percent_change_1h": 0.650488,
"percent_change_24h": -2.7938,
"percent_change_7d": -0.18049,
"market_cap": 12659629994.106007,
"last_updated": "2019-03-04T11:51:04.000Z"
}
}
}
]
}
Но получаю ошибку _CastError (type 'List' is not a subtype of type 'Map' in type cast)
_loadCC() async {
const headers = '2a675b19-8c02-43bd-901a-6dfa0f0cd376';
final response = await http.get(
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?CMC_PRO_API_KEY=${headers}&limit=50");
if (response.statusCode == 200) {
// print(response.body);
// var allData =
// (json.decode(response.body) as Map)['data'] as Map<String, dynamic>;
// var allData = (jsonDecode(response.body).map((e) => e.toList()));
var allData =
(json.decode(response.body) as Map)["data"] as Map<String, dynamic>;
var ccdataList = List<CCData>();
allData.forEach((String key, dynamic value) {
var record = CCData(
name: value['name'],
symbol: value['symbol'],
rank: value['cmc_rank']);
ccdataList.add(record);
});
setState(() {
data = ccdataList;
});
}
}
List<Widget> _buildList() {
return data
.map((CCData f) => ListTile(
title: Text(f.name),
subtitle: Text(f.symbol),
leading: CircleAvatar(child: Text(f.rank.toString())),
trailing: Text('\$${f.price.toString()}'),
))
.toList();
}
}