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.
3
Answers
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>
.As per the error you are getting, it seems like
map['data']
is of typeString
.You need to convert it to JSON format
Map<STring,dynamic>
before passing it toMatchData.fromJson()
MatchData.fromJson
requires aString
. It might work to do:But good chance that your
MatchData
class also has afromMap
method. Then you can use