[英]Binding JSON with property of name “event” in asp.net MVC controller
如何将下面名为“ event”的属性与通过ASP.NET MVC控制器操作列出的类绑定在一起?
类
public class SendGridWebhookRequest
{
public string email { get; set; }
public int timestamp { get; set; }
public string smtp_id { get; set; }
}
请求
{
"status":"5.0.0",
"sg_event_id":"sendgrid_internal_event_id",
"sg_message_id":"sendgrid_internal_message_id",
"event":"bounce",
"email":"email@example.com",
"timestamp":1249948800,
"smtp-id":"<original-smtp-id@domain.com>",
"unique_arg_key":"unique_arg_value",
"category":["category1", "category2"],
"reason":"500 No Such User",
"type":"bounce"
}
您可以提供一个自定义名称,并在json中使用属性指定属性名称:
public class SendGridWebhookRequest
{
public string email { get; set; }
public int timestamp { get; set; }
public string smtp_id { get; set; }
[JsonProperty("event")]
public string MyEvent {get;set;}
}
public string @event {get;set;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.