美文网首页
.net core 读取配置文件 appsettings.jso

.net core 读取配置文件 appsettings.jso

作者: Rinaloving | 来源:发表于2020-10-23 11:13 被阅读0次
{"DeviceSetting": { 
    "Port": "4321", 
    "DeviceInfo": {
      "01": "000-001", 
      "02": "000-002"
    }
  }
}

读取Port

AppConfigurtaion.GetSecondSection("DeviceSetting", "Port").ToString();

读取DeviceInfo

List<DeviceInfoModel> deviceInfos = new List<DeviceInfoModel>();
            dynamic deviceInfo = AppConfigurtaion.GetSection("DeviceSetting:DeviceInfo");
            foreach (var item in deviceInfo)
            {
                DeviceInfoModel model = new DeviceInfoModel() {

                    TurnNum = item.Key,
                    DevId = item.Value
                };
                deviceInfos.Add(model);
            }

引用空间

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

相关文章

网友评论

      本文标题:.net core 读取配置文件 appsettings.jso

      本文链接:https://www.haomeiwen.com/subject/lbqvmktx.html