kfromJsonMap<K, T> method
json转Map<K, T?>,T = 原始数据类型
Map<String, int?>? map = mapStr.kfromJsonMap()
Map<String, String?>? map = mapStr.kfromJsonMap()
Map<int, int?>? map = mapStr.kfromJsonMap()
....
Implementation
Map<K, T?>? kfromJsonMap<K, T>() {
var file = this;
if (file == null || file.isEmpty) {
return null;
}
Map map = jsonDecode(file);
var newMap = <K, T?>{};
map.forEach((key, value) {
newMap[key] = value;
});
return newMap;
}