AppSettings.cs可以对appsettings.json文件进行操作
RsCode提供的读取方式:
读取节点值
csharp
AppSettings.Get(key);
AppSettings.GetValue<T>(key);
更改节点值
例 :添加DataSource节点,值为“RsCodeDemo"
csharp
dynamic obj = AppSettings.GetJObject("custom/custom.json");
obj.DataSource = "RsCodeDemo";
AppSettings.Save(obj);
例:更新DataSource节点,值为JObject
csharp
dynamic obj=AppSettings.GetJObject("json文件路径");
obj.DataSource=JObject.FromObject(new{xxx=value});
AppSettings.Save(obj);
删除节点值
csharp
dynamic obj=AppSettings.GetJObject("json文件路径");
obj.DataSource=null;
AppSettings.Save(obj);
本机调试时,可以在项目appsettings.json文件上右键——属性——将“复制到输出目录”项的值改为“始终复制”