引用Microsoft.Extensions.Configuration

例 appsettiongs.json

  //API资源配置
  "ApiResource": {
    //认证授权中心
    "Authority": "http://localhost:60001",
    //api名称
    "ApiName": "api1",
    //https
    "RequireHttpsMetadata": false

  },

RsCode提供的读取方式:

1.读取json文件中的值

AppSettings.Get(key);
AppSettings.GetValue<T>(key);

2.更改节点 例 :添加DataSource节点,值为“RsCodeDemo"

 dynamic obj = AppSettings.GetJObject("custom/custom.json");
 obj.DataSource = "RsCodeDemo";              
 AppSettings.Save(obj);

例:更新DataSource节点,值为JObject

dynamic obj=AppSettings.GetJObject("json文件路径");
obj.DataSource=JObject.FromObject(new{xxx=value});
AppSettings.Save(obj);

删除值

dynamic obj=AppSettings.GetJObject("json文件路径");
obj.DataSource=null;
AppSettings.Save(obj);

本机调试时,可以在项目appsettings.json文件上右键——属性——将“复制到输出目录”项的值改为“始终复制”**

results matching ""

    No results matching ""