I’m using the json decoder on a List<List<int?>>
json, and I’m having trouble converting the List<dynamic>
to the List<List<int?>>
I’d like to end up with. Is there a simple way to do this?
final jsonString = await rootBundle.loadString('lib/Permutations/$filename.json');
final jsonData = await json.decode(jsonString);
final data = List<List<int?>>.from(jsonData);
(TypeError (type ‘List<dynamic>’ is not a subtype of type
‘List<int?>’)
2
Answers
seems that jsonData is
List<dynamic>
, while you are using that list of dynamic to build a two dimensional list of integers.so, you have two options either
List<dynamic>
toList<int?>
The example below only works for the specified json format shown in
jsonString
., but the code can easily be modified for other formats.