getObject<T> function

T getObject<T>(
  1. Object source,
  2. T f(
    1. Map v
    )
)

Converts JSON string or JSON map source to object.

Implementation

T getObject<T>(Object source, T f(Map v)) {
  if (source == null || source.toString().isEmpty) return null;
  try {
    Map map;
    if (source is String) {
      map = json.decode(source);
    } else {
      map = source;
    }
    return map == null ? null : f(map);
  } catch (e) {
    print('JsonUtil convert error, Exception´╝Ü${e.toString()}');
  }
  return null;
}