I have an appsettings.json file which looks like this:
{ "someSetting": { "subSettings": [ "one", "two", "three" ] } }
When I build my configuration root, and do something like config["someSetting:subSettings"]
it returns null and the actual settings available are something like this:
config["someSettings:subSettings:0"]
Is there a better way of retrieving the contents of someSettings:subSettings
as a list?
json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information. Actually, in ASP.NET Core, the application configuration settings can be stored in different configurations sources such as appsettings.
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<List<string>>()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With