ASP.NET Core Get Json Array using IConfiguration

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

In appsettings.json

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

In Startup.cs

14条回答
  •  感情败类
    2020-11-30 22:18

    You can install the following two NuGet packages:

    using Microsoft.Extensions.Configuration; 
    using Microsoft.Extensions.Configuration.Binder;
    

    And then you'll have the possibility to use the following extension method:

    var myArray = _config.GetSection("MyArray").Get();
    

提交回复
热议问题