asList<T> method

List<T> asList<T>(
  1. String key, [
  2. T toBean(
    1. Map<String, dynamic> json
    )?,
  3. bool decode = false
])

Implementation

List<T> asList<T>(String key, [T Function(Map<String, dynamic> json)? toBean, bool decode = false]) {
  try {
    if (toBean != null && this[key] != null) {
      if (decode && this[key] != 'null') {
        return (json.decode(this[key]) as List).map((v) => toBean(v)).toList().cast<T>();
      }

      return (this[key] as List).map((v) => toBean(v)).toList().cast<T>();
    } else if (this[key] != null) {
      if (T.toString() == 'double') {
        return (this[key] as List).map((v) => double.tryParse(v.toString())).toList().cast<T>();
      }
      return List<T>.from(this[key]);
    }
  } catch (e) {
    _print('json 解析异常,异常值11:"$key":${this[key]},$this');
  }
  return <T>[];
}