You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
941 B

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