StrangeGirlMurph
StrangeGirlMurph

Reputation: 341

String to List<List<dynamic>> - Error: type 'List<dynamic>' is not a subtype of type 'List<List<dynamic>>'

I have a 2d-List with a String and a Map inside like this:

List<List<dynamic>> content = 
[
  [
    "String",
    {
        "one": 23,
        "two: "two"
    }
  ],
];

To store this as a string locally I use json.encode(content).

But when I want to use

json.decode("[["String",{"one": 23,"two: "two"}],]")

to make this a variable of the type List<List<dynamic> I get the error:

type 'List<dynamic>' is not a subtype of type 'List<List<dynamic>>'

How do I solve this? Thanks for the help!

Upvotes: 1

Views: 84

Answers (2)

StrangeGirlMurph
StrangeGirlMurph

Reputation: 341

I solved it myself. I don't really understand why but this works.

content = List.from(json.decode("[["String",{"one": 23,"two: "two"}],]"));

Upvotes: 0

fr3ddie
fr3ddie

Reputation: 406

You need to put List</*here*/> an object what type the List should be. Your list should look like this: List<List<Dynamic>>. Class name instead of it's instance.

Upvotes: 1

Related Questions