© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
78 replies
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);
    }
}
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"
}
{
  "something_here1": "something_here2"
}
and I want to return the number of
"something_here1"
"something_here1"
's. Thanks in advance
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Can't figure out display error avalonia
C#CC# / help
2y ago
❔ An Error I can't figure out
C#CC# / help
3y ago
✅ Can't figure out two error messages - Avalonia
C#CC# / help
2y ago
❔ new to programming and can't figure out
C#CC# / help
3y ago