我通过分步指南学习抖动。因此,当我使用指南中的代码时,它工作正常,但是当我尝试更改JSON URL时,出现错误。据我了解,JSON格式和jsonDecode的问题只是无法解码RIOT JSON,但是如何解决呢?
List _games = await getGames();
Future<List> getGames() async {
//Not working with this JSON URL
String apiUrl = 'https://euw1.api.riotgames.com/lol/match/v4/matchlists/by-account/UZs5l9TT7GLEPfoOZ1eTMqqyJEomgmUHueGQ2aFNHaYTOZI/?api_key=RGAPI-07972f29-94f8-4d54-a2dd-527d4eeb0335';
//Working good with this JSON URL
String apiUrl = 'https://jsonplaceholder.typicode.com/posts';
http.Response response = await http.get(apiUrl, headers: {"Accept": "application/json"});
print(jsonDecode(response.body));
return jsonDecode(response.body);
}
答案 0 :(得分:0)
更改
Future<List>
到
Future<Map<String,dynamic>>
如果您拥有[1, 2, 3]
或["foo", "bar", "baz"]
之类的JSON,则会得到List
,但是如果您拥有{"foo": 1, "bar": 2, "baz": 3}
之类的JSON,则会得到Map . For
“ foo “ you'd get a
字符串and for
真a
布尔,等等。我想你明白了。