C# Azure 函数 - CosmosDB 触发和解析文档数据 [英] C# Azure Function - CosmosDB Trigger and parsing document data

查看:44
本文介绍了C# Azure 函数 - CosmosDB 触发和解析文档数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究在 CosmosDB 触发器上运行的 Azure 函数.微软已经创建了这个例子 https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function 在触发器方面效果很好.

I am working on an Azure Function that runs on the CosmosDB trigger. Microsoft has created this example https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function which works out nicely concerning the trigger.

我现在问自己如何顺利解析返回的文档.我从触发器函数返回的数据来自类 Microsoft.Azure.Documents.Document (IReadOnlyList documents).

I am now asking myself how to parse the returned document in a smooth way. The data I get back from the trigger function is from the class Microsoft.Azure.Documents.Document (IReadOnlyList<Document> documents).

关于如何将这些数据解析为 Json 对象或类似对象的任何好主意?

Any nice idea on how to parse those data into Json objects or comparable?

谢谢!

推荐答案

Document 可以反序列化为任何你想要的类型,例如:

Document can be deserialized to any type you want, for example:

foreach (Document document in documents)
{
    MyClass myClass = JsonConvert.DeserializeObject<MyClass(document.ToString());
}

您还可以读取其任何属性:

You can also read any of its properties:

foreach (Document document in documents)
{
    string myPropertyValue = document.GetPropertyValue<string>("myProperty);
}

这篇关于C# Azure 函数 - CosmosDB 触发和解析文档数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆