asInt method

int asInt(
  1. String key, [
  2. int? defValue
])

解析成int值

Implementation

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