CreateFromDiscriminatorValue如何使用?

huangapple go评论81阅读模式
英文:

How do I use CreateFromDiscriminatorValue?

问题

我有一个从Teams获取通知的Webhook,并希望对返回的数据进行反序列化。

我认为我需要的类型是ChangeNotificationCollectionResponse,但在文档中并没有明确找到它的说明。

不管怎样,如果这是正确的类型,我们应该如何进行反序列化呢?我看到ChangeNotificationCollectionResponse有一个CreateFromDiscriminatorValue方法,但除了一些基本的“这个东西存在”文档之外,我也找不到其他任何文档。

我们是不是要以某种方式使用它,如果是的话,您能提供一个示例吗,或者我们可以只使用普通的JSON反序列化器吗?

谢谢!

英文:

I have a webhook getting notifications from Teams, and want to deserialize the returned data.

I think the type I'm after is ChangeNotificationCollectionResponse but couldn't find this explicitly in the docs anywhere?

Anyhow, if that is the correct type, how are we meant to deserialize it? I see that ChangeNotificationCollectionResponse has a method CreateFromDiscriminatorValue, and again can't find any docs on that aside from the boilerplate "this thing exists" docs.
Do we use that somehow, and if so can you provide an example or can we just use a regular json deserializer?

Thanks!

答案1

得分: 3

"我认为一种方法是创建一个 JsonParseNode 的实例,并调用 GetObjectValue 方法。

var jsonContent = "{\"value\":[{\"subscriptionId\":\"xxx\",\"subscriptionExpirationDateTime\":\"xxx\",\"changeType\":\"created\",...}]}";
var jsonParseNode = new JsonParseNode(JsonDocument.Parse(jsonContent).RootElement);
var collectionResponse = jsonParseNode.GetObjectValue(ChangeNotificationCollectionResponse.CreateFromDiscriminatorValue);

"

英文:

I think one way is to create an instance of JsonParseNode and call the GetObjectValue method.

var jsonContent = "{\"value\":[{\"subscriptionId\":\"xxx\",\"subscriptionExpirationDateTime\":\"xxx\",\"changeType\":\"created\",...]}";
var jsonParseNode = new JsonParseNode(JsonDocument.Parse(jsonContent).RootElement);
var collectionResponse = jsonParseNode.GetObjectValue(ChangeNotificationCollectionResponse.CreateFromDiscriminatorValue);

huangapple
  • 本文由 发表于 2023年4月4日 14:04:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定