Reputation: 79
I learn flutter through the step-by-step guide. So, when I use code from the guide - it's working good, but when I try to change JSON URL, I get the error. As I understand, the problem with JSON format and jsonDecode just can't decode RIOT JSON, but how to fix it?
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);
}
Upvotes: 5
Views: 13075
Reputation: 657238
Change
Future<List>
to
Future<Map<String,dynamic>>
If you have JSON like [1, 2, 3]
or ["foo", "bar", "baz"]
you get a List
, but if you have JSON like {"foo": 1, "bar": 2, "baz": 3}
you get a Map<String,dynamic>
. For "foo"
you'd get a String
and for true
a bool
, and so forth. I guess you get the idea.
Upvotes: 3