[英]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.