{"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;
网友评论