debtFromJSON static method

DebtEntry debtFromJSON(
  1. Map<String, dynamic> json
)

Convert map to DebtEntry.

Implementation

static DebtEntry debtFromJSON(Map<String, dynamic> json) {
  String effectiveDate = '';
  try {
    effectiveDate = json['record_date'] as String;
  } on Exception catch (e) {
    print('DebtEntry.debtFromJSON: record_date exception: $e');
    print('DebtEntry.debtFromJSON: json: $json');
  }

  double governmentHoldings = 0.0, totalDebt = 0.0;
  try {
    final amt = json['intragov_hold_amt'] as String?;
    if (amt != null && amt != 'null') {
      governmentHoldings = double.parse(amt);
    }
  } catch (e) {
    print('DebtEntry.debtFromJSON: intragov_hold_amt exception: $e');
    print('DebtEntry.debtFromJSON: json: $json');
  }

  try {
    final amt = json['tot_pub_debt_out_amt'] as String?;
    if (amt != null && amt != 'null') {
      totalDebt = double.parse(amt);
    }
  } catch (e) {
    print('DebtEntry.debtFromJSON: tot_pub_debt_out_amt exception: $e');
    print('DebtEntry.debtFromJSON: json: $json');
  }

  final change = 1.0;

  return DebtEntry(
    effectiveDate: effectiveDate,
    governmentHoldings: governmentHoldings,
    totalDebt: totalDebt,
    change: change,
  );
}