ASP.NETCORE读取配置至实例
1、1新建ASP.NETCORE web空项目

2、1添加appsettings json文件

3、添加与appseting josn 节点对应的c#的类

4、绑定配置到对象代码using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Configuration;using ASP.NETCORE_配置_Json;namespace ASPCORE_配置绑定到csharp实例{ public class Startup { //通过依赖注入创建Configuration public IConfiguration Configuration { get; set; } public Startup(IConfiguration configuration) { Configuration = configuration; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async (context) => { json1 jsonset = new json1(); Configuration.Bind(jsonset);//绑定到对象 await context.Response.WriteAsync($"linksname:{jsonset.name}"); }); } }}

5、运行完成
