I have a api that I am working with that is going to do a POST of some JSON to one of my server side methods.
I am working on creating some C# classes that map to that JSON’s structure. My problem is one of the fields that is posted to me is named “object” and its a string.
Here is an example of the JSON that is sent to me….
[
{
"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
},]
Here is my issue. How do I tell the model binder to take the json “object” property and map it some a different name in my C# class since object is a reserved word?
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; }
}
Hope this makes sense?
Thanks!
just to have the answer here as well :
try to prefix your c# reserved keyword with “@” if you want to set it as a varible/attribute name.
i.e: