<ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> </ItemGroup>
//获取当前项目所在目录 var contentPath = _hostingEnv.ContentRootPath; //获取wwwroot所在目录 var rootPath = _hostingEnv.WebRootPath;
{
"name": "jeffcky",
"age": 25
}
[HttpPost]
public async Task<IActionResult> Json()
{
var result = string.Empty;
var filePath = _hostingEnv.ContentRootPath + Path.DirectorySeparatorChar + "Json"
+ Path.DirectorySeparatorChar + "Read.json";
using (var streamReader = System.IO.File.OpenText(filePath))
{
result = await streamReader.ReadToEndAsync();
}
var json = new { name = string.Empty, age = 0 };
var data = JsonConvert.DeserializeAnonymousType(result, json);
return View();
}
{
"LogPath": "C:\\Jeffcky_StudyEFCore\\logs",
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"jb51": {
"name": "Jeffcky"
}
}
services.AddSingleton<IConfigurationRoot>(Configuration); services.AddSingleton<IConfiguration>(Configuration);
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile("read.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
{
"jb51": {
"Name": "jeffcky",
"Age": 25
}
}
services.Configure<Person>(Configuration.GetSection("jb51"));
private readonly Models.Person p;
public ReadJsonController(IOptions<Models.Person> option)
{
p = option.Value;
}
[HttpPost]
public IActionResult Json()
{
var age = p.Age;
var name = p.Name;
return View();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有