asNum method

num asNum(
  1. String key
)

解析成int或者double值

Implementation

num asNum(String key) {
  if (this == null) return 0;
  Object? value = this![key];
  if (value == null) return 0;
  if (value is int) return value;
  if (value is double) return value;
  try {
    if (value is String) {
      return value.contains('.') ? double.parse(value) : int.parse(value);
    }
  } catch (e) {
    print(e);
    _print('json parse failed,exception value::\"$key\":$value');
    _printDetail('asNum', key, this);
  }
  return 0;
}