In appsettings.json
{
"MyArray": [
"str1",
"str2",
"str3"
]
}
In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
}
In HomeController
public class HomeController : Controller
{
private readonly IConfiguration _config;
public HomeController(IConfiguration config)
{
this._config = config;
}
public IActionResult Index()
{
return Json(_config.GetSection("MyArray"));
}
}
Es gibt meine Codes oben, ich habe null Wie bekomme ich das Array?
"Clients": [ {..}, {..} ]
, sollten Sie aufrufenConfiguration.GetSection("Clients").GetChildren()
.