countIterableJson static method

int countIterableJson(
  1. dynamic json, {
  2. String separator = ',',
})

Counts items in an iterable or comma-separated string.

Implementation

static int countIterableJson(dynamic json, {String separator = ','}) {
  if (json == null) return 0;
  if (json is Iterable) return json.length;
  if (json is String) {
    return json.split(separator).where((String s) => s.trim().isNotEmpty).length;
  }
  return 0;
}