我有一个非常简单的 Azure HTTP 触发函数,它接收POST
数据:
{
"symbols": ["Azure1", "Azure2", "Azure3"]
}
我的 Azure 功能是:
#r "Newtonsoft.Json"
using System.Net;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string symbols = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "symbol", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
symbols = symbols ?? data?.symbols;
return symbols == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, symbols, JsonMediaTypeFormatter.DefaultMediaType);
}
但是,我收到带有错误消息的 500 响应:Cannot implicitly convert type 'Newtonsoft.Json.Linq.JArray' to 'string'. An explicit conversion exists (are you missing a cast?).
有谁看到我在这里可能出错的地方?我的期望是函数响应是:
["Azure1", "Azure2", "Azure3"]