【发布时间】:2021-08-11 10:20:55
【问题描述】:
我正在开发我的 SlackAPI 应用程序。
我已经创建了模态窗口,当来自这个模态的表单被提交时 - 我收到了一个看起来像这样的 JSON 有效负载(不重要的 JSON 部分被删除)
{
"type":"view_submission",
"view":{
"state":{
"values":{
"IGhn":{
"e5+":{
"type":"static_select",
"selected_option":{
"text":{
"type":"plain_text",
"text":"2021\/8",
"emoji":true
},
"value":"2"
}
}
}
}
},
此有效负载由我的端点正确处理-除了部分-状态-值,它们是空值...
我有这样定义的模型:
public class View
{
...
[JsonProperty("state")]
public State State { get; set; }
...
}
public class State
{
[JsonProperty("values")]
public Dictionary<string, Values> Values { get; set; }
}
public class Values
{
[JsonProperty()] // <- This is the problem
public Dictionary<string, DynamicValue> something { get; set; }
}
public class DynamicValue
{
[JsonProperty("selectedOptions")] // <- This is null
public Dictionary<string, SelectedOption> SelectedOptions { get; set; }
}
如果值(属性名称)是静态的,那没关系,但问题是:IGhn / e5+ 是动态变化的 - 所以反序列化不起作用...
必须说整个 JSON 已正确反序列化,但我无法反序列化 IGhn 下的其余部分(我什至不知道如何为它创建类……反序列化器知道该怎么做…… .)
【问题讨论】:
标签: json deserialization slack-api json-deserialization asp.net-core-5.0