tryJson<T> static method

ModelLessArray<T>? tryJson<T>(
  1. String jsonString
)

Attempts to create a ModelLessArray from a JSON string. The JSON string should represent a list of objects. Each object in the list is converted to a ModelLess instance and added to the array. If parsing fails, the method returns null. jsonString The JSON string to parse. Returns a ModelLessArray containing the parsed ModelLess instances, or null if parsing fails

Implementation

static ModelLessArray<T>? tryJson<T>(String jsonString) {
  try {
    List<dynamic> jsonData = json.decode(jsonString);
    ModelLessArray<T> arrayApiModels = ModelLessArray();
    for (var element in jsonData) {
      ModelLess apiModel = ModelLess.fromMap(element);
      arrayApiModels.set(apiModel);
    }
    return arrayApiModels;
  } catch (e) {
    return null;
  }
}