如何将数组作为 url 参数传递给 Azure Function

How to pass array as url parameter to Azure Function

Azure Functions 参数有点问题 我了解到 url 参数像往常一样发送到 Azure Function "www.asdf.com?myParam=arnold" 并像这样读取

req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "myParam", true) == 0).Value

我不明白的是如何将数组作为参数发送。

对于复杂数据,我建议您将其作为 json 在 POST 请求的正文中传递,然后您可以在动态对象或 Jobject 或自定义 class你可以定义。这是来自 Azure 文档的示例

#r "Newtonsoft.Json"

using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{    
    string jsonContent = await req.Content.ReadAsStringAsync();
    dynamic data = JsonConvert.DeserializeObject(jsonContent);

    log.Info($"WebHook was triggered! Comment: {data.comment.body}");

    return req.CreateResponse(HttpStatusCode.OK, new {
        body = $"New GitHub comment: {data.comment.body}"
    });
}

在此示例中,请求正文在数据对象中反序列化。请求正文包含评论属性,评论包含正文属性如下

{
    "comment": {
        "body": "blablabla"
    }
}

当然在json中你可以根据需要添加任意数量的数组

希望对您有所帮助

一种方法是像这样发送参数:

www.asdf.com?myParam=arnold&myParam=james&myParam=william

然后读作

var params = req
    .GetQueryNameValuePairs()
    .Where(q => string.Compare(q.Key, "myParam", true) == 0)
    .Select(q => q.Value);