appsettings.json
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "option1": "Json", "option2": 2, //对象 "subsection": { "Id": 1, "Name": "Max" }, //数组 "wizards": [ { "Name": "Gand", "Age": "10" }, { "Name": "Harry", "Age": "17" } ], "AllowedHosts": "*"}
Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)//,ILoggerFactory factory { #region Asp.Net Core读取配置文件(JSON文件) { // WriteLine($"option1 = {this.Configuration["option1"]}"); WriteLine($"option2 = {this.Configuration["option2"]}"); //对象获取 WriteLine($"subsection_Id = {this.Configuration["subsection:Id"]}"); WriteLine($"subsection_Name = {this.Configuration["subsection:Name"]}"); //数组获取 WriteLine("wizards"); WriteLine($"wizardsFirst_Name = {this.Configuration["wizards:0:Name"]}"); WriteLine($"wizardsFirst_Age = {this.Configuration["wizards:0:Age"]}"); WriteLine($"wizardsSecond_Name = {this.Configuration["wizards:1:Name"]}"); WriteLine($"wizardsSecond_Age = {this.Configuration["wizards:1:Age"]}"); }
没有评论:
发表评论