1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| using System; using System.IO; using System.Text; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.RegularExpressions; using System.Text.Unicode; using System.Windows.Forms; private void data_init() { configFileDirectory = Path.Combine(Environment.CurrentDirectory, "config"); configJsonFile = Path.Combine(configFileDirectory, "init.json"); jsonString = File.ReadAllText(configJsonFile, Encoding.UTF8); var document = JsonDocument.Parse(jsonString); alarmTime = Int32.Parse(document.RootElement.GetProperty("alarmTime").GetProperty("alarmTime").GetString());
textBox1.Text = alarmTime.ToString(); }
public void updateAlarmTime() { var jsonNode = JsonNode.Parse(jsonString); jsonNode["alarmTime"]["alarmTime"] = alarmTime.ToString(); JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions(); jsonSerializerOptions.WriteIndented = true; jsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); string createText = JsonSerializer.Serialize(jsonNode, jsonSerializerOptions); File.WriteAllText(configJsonFile, createText, Encoding.UTF8); }
|