在Azure function
我的input is ServiceBus queue properties
代码是检索所有属性是 -
using System.Net;
using Newtonsoft.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
string jsonContent = await req.Content.ReadAsStringAsync();
return req.CreateResponse(HttpStatusCode.OK,jsonContent);
}
输出是 -
[
"{\"DeliveryCount\":\"1\",\MessageId\":\"bac52de2d23a487a9ed388f7313d93e5\"}"
]
我想在这个json对象中添加一个属性,如何在azure函数中添加它,以便我可以像下面一样返回修改后的对象 -
[
"{\"DeliveryCount\":\"1\",\MessageId\":\"bac52de2d23a487a9ed388f7313d93e5\",\"MyProperty\":\"TEST\"}"
]
答案 0 :(得分:1)
我认为你可以很容易地做到这一点,通过将JSON反序列化到一个对象,添加你的新属性然后再将它序列化。你甚至不需要具体的类型 - let uuid = UUID(version: .v3, name: "www.widgets.com", nameSpace: .dns)
print(uuid) //3D813CBB-47FB-32BA-91DF-831E1593AC29
应该为你完成这项工作。
例如:
dynamic