Home > OS >  Flutter _InternalLinkedHashMap error on model
Flutter _InternalLinkedHashMap error on model

Time:01-21

Flutter I am getting error while conversing my response to model.

Error Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'

My code:

        var map = json.decode(data);
        MatchData dd = MatchData.fromJson(map['data']);
        print(dd);

In response I am getting object but don't get why this error Is coming.

enter image description here

CodePudding user response:

Please make sure that map["data"] is a type of <String, dynamic>. The error says that you are parsing string to a type of <String, dynamic>.

CodePudding user response:

As per the error you are getting, it seems like map['data'] is of type String.

You need to convert it to JSON format Map<STring,dynamic> before passing it to MatchData.fromJson()

CodePudding user response:

MatchData.fromJson requires a String. It might work to do:

    MatchData dd = MatchData.fromJson(json.encode(map['data']));

But good chance that your MatchData class also has a fromMap method. Then you can use

    MatchData dd = MatchData.fromMap(map['data']);
  • Related