在引用上右击 => 选择管理 Nuget 程序包 => 选择浏览 => 搜索Newtonsoft进行安装
using Newtonsoft.Json;
public string JsPath { get; set; } = $"{cadApp.Path}\\WIdConfigs.json";
public static WeldIDModel ReadJson(string jspath)
{
if (File.Exists(jspath))
{
string jstr = File.ReadAllText(jspath);
return JsonConvert.DeserializeObject<WeldIDModel>(jstr);
}
return new WeldIDModel() { OutBoxCmbx = new List<string>() { "圆", "椭圆" } };
}
public static void WriteJson(WeldIDModel wim, string jspath)
{
if (File.Exists(jspath))
{
if (wim.OutBoxCmbx.Count == 0) wim.OutBoxCmbx = new List<string>() { "圆", "椭圆" };
string jstr = JsonConvert.SerializeObject(wim);
File.WriteAllText(jspath, jstr);
}
}