En appsettings.json
{
"MyArray": [
"str1",
"str2",
"str3"
]
}
En Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
}
En HomeController
public class HomeController : Controller
{
private readonly IConfiguration _config;
public HomeController(IConfiguration config)
{
this._config = config;
}
public IActionResult Index()
{
return Json(_config.GetSection("MyArray"));
}
}
Hay mis códigos arriba, obtuve un valor nulo ¿Cómo obtener la matriz?
"Clients": [ {..}, {..} ]
, debe invocarConfiguration.GetSection("Clients").GetChildren()
.