skip to Main Content

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

3

Answers


  1. 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>.

    Login or Signup to reply.
  2. 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()

    Login or Signup to reply.
  3. 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']);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search