[英]Change feed iterator content deserialization
Currently, I'm looking for ways to deserialize entities from Change Feed Iterator content with System.Text.Json.目前,我正在寻找使用 System.Text.Json 从 Change Feed Iterator 内容中反序列化实体的方法。
I found this example from the documentation, but it uses Newtonsoft.Json and I don't like an approach with JObject and JsonTextReader.我从文档中找到了这个示例,但它使用了 Newtonsoft.Json,我不喜欢使用 JObject 和 JsonTextReader 的方法。 Is there are any way to make it more properly and clean?
有什么办法可以让它更干净整洁吗?
I've tried to make something like this, but my approach doesn't work.我试图做这样的事情,但我的方法不起作用。
ResponseMessage response = await iterator.ReadNextAsync();
var entities = await JsonSerializer.DeserializeAsync<IEnumerable<CosmosEntity1>>(response.Content);
The response stream you get is not an IEnumerable
of your documents but rather a class that contains the documents as one of its properties.您获得的响应 stream 不是您的文档的
IEnumerable
,而是包含文档作为其属性之一的 class 。 Try creating the following class:尝试创建以下 class:
public class ExampleResponse
{
public string _rid { get; set; }
public List<CosmosEntity1> Documents { get; set; }
public int _count { get; set; }
}
and deserialize your stream to that class.并将您的 stream 反序列化为 class。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.