asBool method

bool asBool(
  1. String key, [
  2. bool? defValue
])

解析成bool值

Implementation

bool asBool(String key, [bool? defValue]) {
  if (this == null) return defValue ?? false;
  Object? value = this![key];
  if (value == null) return defValue ?? false;
  if (value is bool) return value;
  if (value is num) return value == 1;
  if (value == 'true') return true;
  if (value == '0') return false;
  if (value == '1') return true;
  if (value == 'false') return false;
  _print('json parse failed,exception value::\"$key\":$value');
  _printDetail('asBool', key, this);
  return defValue ?? false;
}