asBeans<T> method Null safety

T? asBeans<T>(
  1. List<String> keys,
  2. dynamic toBean(
    1. Map json
    )
)

多字段解析成model

Implementation

T? asBeans<T>(List<String> keys, Function(Map json) toBean) {
  if (this == null) return null;
  for (String key in keys) {
    try {
      Object? obj = this![key];
      if (obj != null && _isClassBean(obj)) {
        return toBean(this![key]);
      } else if (obj != null && obj is String) {
        Map _map = jsonDecode(obj);
        return toBean(_map);
      }
    } catch (e) {
      print(e);
      _print('json parse failed,exception value::\"$key\":${this![key]}');
      _printDetail('asBeans', key, this);
    }
  }

  return null;
}