小编ris*_*ssa的帖子

如何从 appsettings.json 文件中的对象数组读取值

我的 appsettings json 文件

       {
         "StudentBirthdays": [
                { "Anne": "01/11/2000"},
                { "Peter": "29/07/2001"},
                { "Jane": "15/10/2001"},
                { "John": "Not Mentioned"}
            ]
        }
Run Code Online (Sandbox Code Playgroud)

我有一个单独的配置类。

public string GetConfigValue(string key)
{
    var value = _configuration["AppSettings:" + key];
    return !string.IsNullOrEmpty(value) ? Convert.ToString(value) : string.Empty;
}
Run Code Online (Sandbox Code Playgroud)

我尝试过的是,

 list= _configHelper.GetConfigValue("StudentBirthdays");
Run Code Online (Sandbox Code Playgroud)

对于上述内容,我没有得到这些值。

我如何读取这些值(我想分别读取学生的姓名和他的生日)。

任何帮助表示赞赏

c# arrays configuration object appsettings

3
推荐指数
1
解决办法
4959
查看次数

标签 统计

appsettings ×1

arrays ×1

c# ×1

configuration ×1

object ×1