[英]ASP.NET MVC ModelBinder Custom Field Mapping
我有一个正在使用的api,它将对我的服务器端方法之一执行一些JSON POST。
我正在创建一些映射到该JSON结构的C#类。 我的问题是发布给我的字段之一名为“对象”及其字符串。
这是发送给我的JSON的示例。...
[
{
"subscription_id": "1",
"object": "user",
"object_id": "1234",
"changed_aspect": "media",
"time": 1297286541
},
{
"subscription_id": "2",
"object": "tag",
"object_id": "nofilter",
"changed_aspect": "media",
"time": 1297286541
},]
这是我的问题。 我如何告诉模型绑定器采用json“对象”属性,并将其映射为C#类中的其他名称,因为对象是保留字?
public class InstagramUpdate
{
public string subscription_id { get; set; }
public string object_id { get; set; }
public string object { get; set; } //<-- what should I do here??
public string changed_aspect { get; set; }
public int time { get; set; }
}
希望这有意义吗?
谢谢!
只是在这里也有答案:
如果要将c#保留关键字设置为变量/属性名称,请尝试在其前面加上“ @”前缀。
即:
public class InstagramUpdate
{
public string subscription_id { get; set; }
public string object_id { get; set; }
public string @object { get; set; } //object will be here the prop name
public string changed_aspect { get; set; }
public int time { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.