【发布时间】:2021-12-13 08:43:44
【问题描述】:
目前,我正在寻找使用 System.Text.Json 从 Change Feed Iterator 内容中反序列化实体的方法。
我从文档中找到了 this 示例,但它使用 Newtonsoft.Json,我不喜欢使用 JObject 和 JsonTextReader 的方法。 有什么办法可以让它更干净整洁吗?
我尝试过制作这样的东西,但我的方法不起作用。
ResponseMessage response = await iterator.ReadNextAsync();
var entities = await JsonSerializer.DeserializeAsync<IEnumerable<CosmosEntity1>>(response.Content);
【问题讨论】:
-
在您的代码示例中什么不起作用?
-
@404 它抛出 System.Text.Json.JsonException 并显示一条消息“System.Text.Json.JsonException:JSON 值无法转换为 System.Collections.Generic.IEnumerable`1[ChangeFeedSubscriber .Entities.CosmosEntity1]".
-
尝试将其反序列化到 List
中。但是,如果您向我们展示您的实体模型和响应内容中的 json 示例,则会更容易理解问题。 -
@Repulse3 不幸的是仍然有异常消息“无法将 JSON 值转换为 System.Collections.Generic.List`1[ChangeFeedSubscriber.Entities.CosmosEntity1]”。
-
执行
var json = new StreamReader(response.Content).ReadToEnd();时得到的JSON是什么?
标签: c# azure-cosmosdb system.text.json azure-cosmosdb-changefeed