Ton*_*ony 5 azure azure-functions
我有这个功能
[FunctionName("json")]
public static JsonResult json
(
[HttpTrigger(AuthorizationLevel.Anonymous, new string[] { "POST", "GET", "DELETE", "PATCH", "PUT" })]
HttpRequest req,
TraceWriter log
)
{
return new JsonResult(new
{
Nome = "TONY",
Metodo = req.Method.ToString()
});
}
Run Code Online (Sandbox Code Playgroud)
问题是它正在返回
{"nome":"TONY","metodo":"GET"}
Run Code Online (Sandbox Code Playgroud)
我想让它回来
{"Nome":"TONY","Metodo":"GET"}
Run Code Online (Sandbox Code Playgroud)
在 ASP.Net Core 2 中我使用了这个:
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());
// Keep the Case as is
Run Code Online (Sandbox Code Playgroud)
如何配置 Azure Functions 来做到这一点?
你可以这样做:
[FunctionName("json")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequestMessage req, TraceWriter log)
{
return new HttpResponseMessage(HttpStatusCode.OK)
{
RequestMessage = req,
Content = new StringContent(
content: JsonConvert.SerializeObject(new
{
Nome = "TONY",
Metodo = req.Method.ToString()
}),
encoding: System.Text.Encoding.UTF8,
mediaType: "application/json")
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2118 次 |
| 最近记录: |