W pliku appsettings.json
{
"MyArray": [
"str1",
"str2",
"str3"
]
}
W Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
}
W HomeController
public class HomeController : Controller
{
private readonly IConfiguration _config;
public HomeController(IConfiguration config)
{
this._config = config;
}
public IActionResult Index()
{
return Json(_config.GetSection("MyArray"));
}
}
Powyżej znajdują się moje kody, mam null Jak pobrać tablicę?
"Clients": [ {..}, {..} ]
, powinieneś wywołaćConfiguration.GetSection("Clients").GetChildren()
.