I want to populate a drop down list with a list of servers I have in a json file. So I want to retrieve the list from json and use that list to add all of the servers to my drop down. I have a simple json file with a simple array in it. In an ideal world, all I want to do is something like this:
public static IConfigurationRoot Configuration { get; set; }
public static void Main(string[] args = null)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
List<string> servers = Configuration["servers"];
foreach (string server in servers)
{
cboSelectServer.Items.Add(server);
}
}
And my appsettings.json file looks like this:
{
"servers": ["server1", "server2"]
}
The message I get is
Cannot implicitly convert type 'string' to System.Collections.Generic.List<string>
What is really confusing me is that it obviously understands Configuration["servers"] is a list because if I look at Configuration["servers:0"] I get my first server.
using System.Linq;