【发布时间】:2021-11-17 08:49:11
【问题描述】:
我的 appsettings json 文件
{
"StudentBirthdays": [
{ "Anne": "01/11/2000"},
{ "Peter": "29/07/2001"},
{ "Jane": "15/10/2001"},
{ "John": "Not Mentioned"}
]
}
我有一个单独的配置类。
public string GetConfigValue(string key)
{
var value = _configuration["AppSettings:" + key];
return !string.IsNullOrEmpty(value) ? Convert.ToString(value) : string.Empty;
}
我尝试过的是,
list= _configHelper.GetConfigValue("StudentBirthdays");
对于上述我没有得到值。
我如何读取这些值(我想分别读取学生的姓名和他的生日)。
感谢任何帮助
【问题讨论】:
-
你得到的list的价值是多少?
-
我建议使用
.GetSection并遍历它。 -
@Serge 我没有得到任何列表值。(null)
-
@Llama 你的意思是 "_configHelper.GetSection("StudentBirthdays"); ",在配置类中实现一个单独的 GetSection 方法之后?
-
我的意思是
_configuration.GetSection,是的,可能是在_configHelper类中提供对它的访问。
标签: c# arrays object configuration appsettings