using System; using System.Xml; using Newtonsoft.Json; using Formatting = Newtonsoft.Json.Formatting; namespace CK.SCP.Utils { public class JsonHelper { public static T ReadConfigFromFile(string fileName) where T : new() { var t = new T(); var strData = FileHelper.ReadFile(fileName); try { t = JsonConvert.DeserializeObject(strData); } catch { MessageHelper.ShowError($"配置文件{fileName}错误,请重新配置!"); } return t; } public static void WriteConfigToFile(string fileName, T t) where T : new() { var strData = JsonConvert.SerializeObject(t, Formatting.Indented); // MessageHelper.ShowInfo(strConfig); FileHelper.WriteFile(fileName, strData); } public static string GetJson(T t) { return JsonConvert.SerializeObject(t, Formatting.Indented); } } }