如何在Azure函数中的local.settings.json文件中设置数组值 [英] how to set an array value in local.settings.json file in azure functions
问题描述
当我尝试将数组作为 local.settings.json 文件中的值之一插入时:
When I try to insert an array as one of the Values in local.settings.json file:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
"myArray": [
{
"key1": "value1",
"key2": "value2"
},
{
"key1": "value3",
"key2": "value4"
}
]
},
"ConnectionStrings": {
"SQLConnectionString": "myConnectionString"
}
}
我开始遇到例外.可以在 local.settings.json
文件中使用数组吗?如果可以的话,正确的格式是什么?
I start getting exceptions. Can arrays be used in the local.settings.json
file? And if they can, what's the correct format?
推荐答案
现在可以!
我的本地设置文件如下:
My local settings file looks like this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
},
"CustomArray": [
{
"CustomProp1": "foo0",
"CustomProp2": "bar0"
},
{
"CustomProp1": "foo1",
"CustomProp2": "bar1"
}
]
}
当部署到Azure时,我的配置如下所示:
My config when deployed to Azure looks like this:
然后,要在启动"中解析该数组,我会看到以下内容:
Then, to resolve the array in my Startup, I have something like this:
var settings = new List<CustomSetting>();
config.GetSection("CustomArray").Bind(settings);
...其中 CustomSetting
是这样的类:
... where CustomSetting
is a class like this:
public class CustomSetting
{
public string CustomProp1 { get; set; }
public string CustomProp2 { get; set; }
}
我正在使用 Microsoft.Extensions.Configuration
Nuget程序包的版本3.1.5和 Microsoft.NET.Sdk.Functions
Azure函数的版本3.0.7SDK.
I am using version 3.1.5 of the Microsoft.Extensions.Configuration
Nuget package, and version 3.0.7 of the Microsoft.NET.Sdk.Functions
Azure Functions SDK.
这篇关于如何在Azure函数中的local.settings.json文件中设置数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!