如何在Azure函数(v2)中的Pascal Case中返回JSON?

时间:2018-03-17 01:11:28

标签: 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()
    });
}

问题是它正在返回

{"nome":"TONY","metodo":"GET"}

我希望它返回

{"Nome":"TONY","Metodo":"GET"}

在ASP.Net Core 2中,我使用了这个:

services.AddMvc()
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());
// Keep the Case as is

如何配置Azure功能以实现这种方式?

2 个答案:

答案 0 :(得分:4)

你可以这样做:

asInstanceOf

答案 1 :(得分:0)

将JsonPropertyAttribute添加到属性中,并通过文件顶部的#r“ Newtonsoft.Json”包含Json.NET。

#r "Newtonsoft.Json"

using Newtonsoft.Json;

并装饰属性

[JsonProperty(PropertyName = "nome" )]
public string Nome { get; set; }

[JsonProperty(PropertyName = "metodo" )]
public string Metodo { get; set; }