asInt method

int asInt(
  1. String key, {
  2. int defaultNum = 0,
})

Implementation

int asInt(String key, {int defaultNum = 0}) {
  final Object? value = this[key];
  if (value == null) {
    return defaultNum;
  }
  if (value is int) {
    return value;
  }
  if (value is double) {
    return value.toInt();
  }
  try {
    String value0 = value.toString();
    if (value0.isEmpty) {
      return defaultNum;
    }
    final int result = int.parse(value0);
    return result;
  } catch (e) {
    _print('json 解析异常,异常值,期望int值:"$key":$value');
  }
  return 0;
}