C#C
C#2y ago
Mek

✅ Working With Json

public static bool CreateJsonFile()
{
    Dictionary<string, bool> newDict = new Dictionary<string, bool>();
    newDict.Add("agree", false);

    var jsonData = JsonSerializer.Serialize(newDict);

    try
    {
        File.WriteAllText(_jsonFile, jsonData);
        return true;
    }
    catch (Exception ex)
    {
        ColorPrint.WriteLine(ex.Message, ConsoleColor.Red);
        return false;
    }
}
this current code creates a json file that looks simply like
{"agree": false}
however I want to add two new values to it so that it looks like
{
  "agree": false,
  "username": "",
  "password": ""
}
but I'm not sure how to edit the current code. Thanks
Was this page helpful?