好记性不如烂笔头。

.NET Core 通过索引器实现读取.json配置文件

   public class AppSettings
{
IConfiguration config;
public AppSettings():this("appsettings.json") { }
public AppSettings(string jsonFileName)
{
var configBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(jsonFileName);
config = configBuilder.Build();
}
public string this[string name]
{
get { return config.GetSection(name).Value;}
}
}

用法

AppSettings get = new AppSettings();
string v = get["key"];