appsettings 文件的结构如下所示,我正在尝试将设置加载为 Dictionary
"ConversionSettings": {
"jan": {
"10": [
"Early1",
"Early2",
"Early3"
],
"20": [
"Normal1",
"Normal2",
"Normal3"
],
"31": [
"Late1",
"Late2"
]
},
"feb": {
"5": [
"Early1",
"Early2",
"Early3"
],
"15": [
"Normal1",
"Normal2",
"Normal3"
],
"20": [
"Late1",
"Late2"
]
},
....
}
要在应用程序启动时加载设置,我正在编写此代码
.Configure<Dictionary<string, Dictionary<int, List<string>>>>(hostingContext.Configuration.GetSection("ConversionSettings"))
结果是带有 2 个键“jan”和“feb”的设置,但值部分为空,应该是 Dictionary
如果我将 key 的数据类型从 int 转换为 string 正确加载即
<块引用>Dictionary
我们能否将 appsettings 中的字符串值映射到字典