ASP.NET MVC ModelBinder自定义字段映射

Mat*_*att 2 c# asp.net-mvc json instagram

我有一个我正在使用的api,它将对我的一个服务器端方法执行一些JSON的POST.

我正在创建一些映射到JSON结构的C#类.我的问题是发布给我的字段之一被命名为"object"及其字符串.

以下是发送给我的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
},]
Run Code Online (Sandbox Code Playgroud)

这是我的问题.如何告诉模型绑定器获取json"object"属性并在C#类中将其映射为一个不同的名称,因为object是一个保留字?

 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; }
}
Run Code Online (Sandbox Code Playgroud)

希望这有道理吗?

谢谢!

Ale*_*eta 5

只是为了得到答案:

如果要将其设置为变量/属性名称,请尝试使用"@"为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; }
}
Run Code Online (Sandbox Code Playgroud)