toMapList method
JSON 字符串转为 List
Implementation
List<Map<String, dynamic>>? toMapList(String? jsonStr) {
if (jsonStr == null || jsonStr.isEmpty) return null;
try {
final decoded = json.decode(jsonStr);
if (decoded is! List) return null;
return decoded
.map((e) {
if (e is Map<String, dynamic>) {
return e;
} else if (e is String) {
final innerDecoded = json.decode(e);
return innerDecoded is Map<String, dynamic> ? innerDecoded : null;
}
return null;
})
.whereType<Map<String, dynamic>>()
.toList();
} catch (e) {
logger.e("JSON 转 Map 列表失败: $e");
return null;
}
}