How do I return JSON from an Azure Function

前端 未结 7 1429
逝去的感伤
逝去的感伤 2021-02-06 20:43

I am playing with Azure Functions. However, I feel like I\'m stumped on something pretty simple. I\'m trying to figure out how to return some basic JSON. I\'m not sure how to cr

7条回答
  •  渐次进展
    2021-02-06 21:35

    The easiest way is perhaps to

    public static async Task Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "/jsontestapi")] HttpRequest req,
        ILogger log)
    {
        return new JsonResult(resultObject);
    }
    

    Will set the content-type to application/json and return the json in the response body.

提交回复
热议问题