How to extract a list from appsettings.json in .net core

后端 未结 5 1912
耶瑟儿~
耶瑟儿~ 2020-12-24 00:13

I have an appsettings.json file which looks like this:

{
    \"someSetting\": {
        \"subSettings\": [
            \"one\",
            \"two\",
                 


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 00:49

    Assuming your appsettings.json looks like this:

    {
      "foo": {
        "bar": [
          "1",
          "2",
          "3"
        ]
      }
    }
    

    You can extract the list items like so:

    Configuration.GetSection("foo:bar").Get>()
    

提交回复
热议问题