8

I have a JSON data to post to http, this JSON data has a var named params:

{
 "method": "...",
 "params": [ ... ],
 "session": "...",
 "id": 1
}

I want to link every request and response to a class in my Models. How can I either use the name params for the attribute or make the attribute name change as I serialize my class to JSON format? I am using ASP.NET MVC 4 and JSON.NET framework on visual studio 2013 Ultimate edition.

1 Answers1

19

A property named params (or any other keyword) can be used in C# classes as long as you escape the name using the @ prefix:

class MyClass
{
    public string method { get; set; }
    public Whatever @params { get; set; }
}
Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519