In my .NET Core application, I am trying to read data from appsettings.json
.
I have this configuration in appsettings.json
:
"ServiceDetails": {
"CellDetails": {
"ScenarioName": [ 4, 5 ],
"ServiceName": [ 5, 5 ]
}
}
I would like to read this and convert into list like this:
scenario name, 4,5
service name, 5,5
Model class for the above list:
public class CellDetails
{
public string CellKeyValue { get; set; }
public int Row { get; set; }
public int Column { get; set; }
}
I am trying something like this
var serverUrl = configuration.GetSection("ServiceDetails")
.GetSection("CellDetails").Get<string[]>();
Above code doesn’t work, can someone help me to fix this? Any help would be appreciated.
2
Answers
Do you want this?
result:
Update:
Try to create a model ServiceDetails like:
Then in appsettings.json :
Then
result:
It’s not Recommended way do this but if you don’t change the schema this will be helpful :
and this is the output:
output