Reputation: 1007
I have a appsettings.json file as below
{
"student":{
"subject": "0;3",
"grade": "4;5"
}
}
I want to read the section student and add it to a dictionary. My dictionary keys will be subject and grade. For that I am doing the following to get the section student. I don't want to define any class to store the section student.
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location))
.AddJsonFile("appsetting.json").Build();
var result= config.GetSection("student");
But values are not getting populated in result.
Thanks for your help.
Upvotes: 0
Views: 866
Reputation: 21
you should create a separate object that contains the values. check this documentation
Upvotes: 2