How do I return JSON from an Azure Function

前端 未结 7 1432
逝去的感伤
逝去的感伤 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:36

    I had a similar issue and this seemed to be the most popular post with no answer. After figuring what node does the below should work and give you exactly what you are after. The other examples still returns a string representation wheres this will return JSON.

    Remember to declare using System.Text; and also add:

    return JsonConvert.SerializeObject(person);
    

    to the GetJson function as per Juunas response.

        return new HttpResponseMessage(HttpStatusCode.OK)
           {
               Content = new StringContent(GetJson(), Encoding.UTF8, "application/json")
           };

提交回复
热议问题