asBean<T> method

T? asBean<T>(
  1. String key,
  2. dynamic toBean(
    1. Map json
    )
)

解析成 model

Implementation

T? asBean<T>(String key, Function(Map json) toBean) {
  if (this == null) return null;
  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('asBean', key, this);
  }
  return null;
}