猿问

从 appsettings c# 中读取 json 数组

我的数组中有 appsettings.json


"steps": [

{

  "name": "IMPORT",

  "enabled": true

},

{

  "name": "IMPORT_XML",

  "enabled": true

},

{

  "name": "COMPARE",

  "enabled": true

},

{

  "test_name": "COMPARE_TABLE",

  "enabled": true

}]

在我的课堂上,我试图用 IConfigurationRoot _configurationRoot


我试过了:


var procSteps = _configurationRoot.GetSection("steps");

foreach (IConfigurationSection section in procSteps.GetChildren())

{

    var key = section.GetValue<string>("test");

    var value = section.GetValue<string>("enabled");

}

和:


var procSteps = _configurationRoot.GetSection("ExecutionSteps")

            .GetChildren()

            .Select(x => x.Value)

            .ToArray();

但他们都没有找回我的价值观。有谁知道这是什么情况以及访问此类数组值的正确方法是什么?


ABOUTYOU
浏览 710回答 1
1回答
随时随地看视频慕课网APP
我要回答