How do I return JSON from an Azure Function

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

    JSON is pretty easy, Newtonsoft.Json library is a special case. You can include it by adding this at the top of the script file:

    #r "Newtonsoft.Json"
    
    using Newtonsoft.Json;
    

    Then your function becomes:

    public static string GetJson() 
    {
      var person = new Person();
      person.FirstName = "John";
      person.LastName = "Doe";
    
      person.Orders = new List();
      person.Orders.Add(new Order() { Id=1, Description="..." });
    
      return JsonConvert.SerializeObject(person);
    }
    

提交回复
热议问题