【发布时间】:2021-03-18 07:02:26
【问题描述】:
我需要一点帮助来创建 C# 类来映射来自 FCM 令牌信息 api (https://developers.google.com/instance-id/reference/server#get_information_about_app_instances) 的 json 响应:
{
"application": "com.chrome.windows",
"subtype": "wp:www.mydomain.com/#A1249A346-7458-45BB-A0F2-2AC4856BB-V2",
"scope": "*",
"authorizedEntity": "8212312155",
"rel": {
"topics": {
"topic1": {
"addDate": "2020-12-06"
}
}
},
"platform": "BROWSER"
}
其中 topic1 不是属性名称,而是一个值,而属性名称 topics 包含主题列表。
我其实不知道如何在上面的json中表示topics。
【问题讨论】:
-
public Dictionary<string, Topic> Topics {get;set;} -
Visual Studio 粘贴菜单 => 选择性粘贴 -> 将 Json 粘贴为类
-
如果您想更好地命名属性,您可以随意更改它们,并在属性上方添加 [JsonProperty("topic1")]。所以序列化不会出现任何错误
标签: c# .net asp.net-core asp.net-core-2.0 asp.net-core-3.1