ASP.NET Core Get Json Array using IConfiguration

后端 未结 14 2105
失恋的感觉
失恋的感觉 2020-11-30 21:49

In appsettings.json

{
      \"MyArray\": [
          \"str1\",
          \"str2\",
          \"str3\"
      ]
}

In Startup.cs

14条回答
  •  北海茫月
    2020-11-30 22:26

    In ASP.NET Core 2.2 and later we can inject IConfiguration anywhere in our application like in your case, you can inject IConfiguration in HomeController and use like this to get the array.

    string[] array = _config.GetSection("MyArray").Get();
    

提交回复
热议问题