C#C
C#2y ago
Mek

✅ Can't figure out json logic

internal static int GetUsers()
{
    try
    {
        var fileData = File.ReadAllText(_usersPath);
        var jsonData = JsonSerializer.Deserialize<List<UserModel>>(fileData);

        if (jsonData != null)
        {
            return jsonData.Count;
        }
        else
        {
            return 0;
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}
the purpose of this function is to simply return the number of users in the json file. The json file is structured like this
{
  "something_here1": "something_here2"
}
and I want to return the number of "something_here1"'s. Thanks in advance
Was this page helpful?