Flutter报错:Unhandled Exception: type ‘_Map<String, dynamic>‘ is not a subtype of type ‘String‘

This is because when we use the jsondecode() function, we mistakenly bring the _Map<String, dynamic> type into the jsondecode function.

The jsondecode function itself is to decode the json string into a json object of type _Map<String, dynamic>.

Then you can use forEach to traverse the key-value pairs of the json object.

For example, jsonMap is a _Map<String, dynamic> type:

jsonMap.forEach((key, value) {
    print('Key: $key');
    print('Value: $value');
    print('------');
  });

Or use an iterator to traverse:

var iterator = jsonMap.entries.iterator;
  while (iterator.moveNext()) {
    var entry = iterator.current;
    print('Key: ${entry.key}');
    print('Value: ${entry.value}');
    print('------');
  }

Guess you like

Origin blog.csdn.net/DongShanYuXiao/article/details/132115708