尝试解析 JSON 时,InternalLinkedHashMap<String, dynamic>' 不是类型 'FutureOr<List<dynamic> 的子类型

Vee*_*Xit 5 json dart flutter

我通过分步指南学习颤振。因此,当我使用指南中的代码时 - 它运行良好,但是当我尝试更改 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);
}
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 3

改变

Future<List>
Run Code Online (Sandbox Code Playgroud)

Future<Map<String,dynamic>>
Run Code Online (Sandbox Code Playgroud)

如果你有类似的 JSON [1, 2, 3],或者["foo", "bar", "baz"]你会得到一个List,但是如果你有类似的 JSON,{"foo": 1, "bar": 2, "baz": 3}你会得到一个Map<String,dynamic>. 因为"foo"你会得到 aStringtruea bool,等等。我想你明白了。