toIntListJson static method

List<int>? toIntListJson(
  1. dynamic json
)

Converts JSON to a list of integers.

Implementation

static List<int>? toIntListJson(dynamic json) {
  if (json == null) return null;
  if (json is List<int>) return json;
  if (json is List<dynamic>) return json.map(toIntJson).whereType<int>().toList();
  if (json is String) {
    return json.split(',').map((String s) => int.tryParse(s.trim())).whereType<int>().toList();
  }
  return null;
}