asArray2d<T> method
Two-dimensional array 二维数组解析
Implementation
List<List<T>>? asArray2d<T>(String key, [Function(Map json)? toBean]) {
if (this == null) return null;
try {
Object? obj = this![key];
if (toBean != null && obj != null) {
if (obj is List) {
if (obj.isEmpty) return [];
if (obj.is2dArray) {
return obj.map((ele) => ele.map((v) => toBean(v)).toList().cast<T>()).toList().cast<List<T>>();
}
return [];
} else if (obj is String) {
List _list = jsonDecode(obj);
if (_list.is2dArray) {
return _list.map((ele) => ele.map((v) => toBean(v)).toList().cast<T>()).toList().cast<List<T>>();
}
return [];
}
} else if (obj != null) {
if (obj is List) {
return _array2dFrom<T>(obj, key);
} else if (obj is String) {
return _array2dFrom<T>(jsonDecode(obj), key);
}
}
} catch (e) {
print(e);
_print('json parse failed,exception value::\"$key\":${this![key]}');
_printDetail('asList', key, this);
}
return null;
}