【发布时间】:2020-08-12 06:11:39
【问题描述】:
我想从 appsettings.json 读取这个设置:
"CountryPhoneSetting": [
{
"US": {
"DialCode": "+1",
"CanSMS": true,
"CanVerify": true
}
}
]
这是我要存储它的类:
public class CountryPhoneSetting
{
public IDictionary<string, CountryDetails> CountryInfo {
get;set;
}
public class CountryDetails
{
public string DialCode { get; set; }
public bool CanSMS { get; set; }
public bool CanVerify { get; set; }
}
}
我已经使用了 stackoverflow 解决方案,但它们都不起作用。
请帮忙
【问题讨论】:
-
我想将它添加到服务中,例如:services.Configure
(Configuration.GetSection("CountryPhoneSetting")); -
向我们展示无效的代码。
-
Configuration.GetSection("CountryPhoneSetting").GetChildren().ToList() .ToDictionary(x => x.Key, x => x.Value);这导致空
-
奇怪的是 Json 是 "CountryPhoneSetting": [ { "US": { "DialCode": "+1", "CanSMS": true, "CanVerify": true } } ],额外的
[]使它成为Dictionary<string, CountryPhoneSetting>[]可以显示一个在字典中有多个条目的配置.. 它会是一个元素的多个字典吗?
标签: c# asp.net json asp.net-core