Как получить дочерние элементы, указав дочернее имя в файле настроек json?
"AppSettings":
{"AzureAd":
{
"Instance": "https://login.microsoftonline.com/",
"Domain": "abc.com",
"TenantId": "90836560-70ab-4caa-9e10-7e80b43d8d5a"
}
}
Как получить значение "Экземпляра" в файле класса. Я попробовал это ниже, который не работает
var symmetrickey = _configuration.GetSection("AppSettings:AzureAd:Instance").GetChildren()
.Select(configSection => configSection.Value);
где я получаю массив узлов "AzureAd", когда я изменяю, как показано ниже
var symmetrickey = _configuration.GetSection("AppSettings:AzureAd").GetChildren()
.Select(configSection => configSection.Value);
Но я хочу значение "Instance"/"TenantId", особо упомянув любой из текстов.
1 ответ
JSON для настройки приложения не должен начинаться с ключа json. Удалите «Настройки приложения»:
{
"AzureAd":
{
"Instance": "https://login.microsoftonline.com/",
"Domain": "abc.com",
"TenantId": "90836560-70ab-4caa-9e10-7e80b43d8d5a"
}
}
Чтобы получить значение
var symmetrickey = _configuration.GetSection("AzureAd:Instance").Value;