asInts method Null safety

int asInts(
  1. List<String> keys,
  2. [int? defValue]
)

解析成ints值

Implementation

int asInts(List<String> keys, [int? defValue]) {
  if (this == null) return defValue ?? 0;
  for (String key in keys) {
    Object? value = this![key];
    if (value == null) continue;
    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('asInts', key, this);
    }
  }
  return defValue ?? 0;
}