.net 使用ConfigurationBuilder 读取配置json文件

 

hosting.josn 配置

 

 

读取

var config= new ConfigurationBuilder()
.AddJsonFile("hosting.json", optional: true)
.Build();

 

 

 取值

  string sqlString = config.GetSection("server.urls").Value;
   //读取参数的属性,要读取的时候每一级里面加入:即可
   string a = config.GetSection("多级:一:一点一").Value;

相关链接

https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.extensions.configuration.configurationroot?view=dotnet-plat-ext-6.0

posted @ 2022-08-03 09:02  魔法少女郭德纲啊  阅读(512)  评论(0)    收藏  举报