我正在用 C# 开发 Telegram 机器人,但难以实现Message
类型。根据API 文档,chat
字段可以是 typeUser
或 type GroupChat
。我如何在 C# 中实现它?
到目前为止,我只能使用以下代码Newtonsoft.Json
:
public class Update {
....
[JsonProperty("chat")]
public User chat { get; set; }
[JsonProperty("chat")]
public GroupChat group_chat { get; set; }
....
}
但它不适用于我的 WebAPI 2 控制器方法,因为我Message
使用FromBody
属性反序列化:
public async Task<HttpResponseMessage> Post(string token, [FromBody] Update update)
(类型Update
有一个message
类型的字段Message
)
有没有更好的方法来实现Message
类型?