I have the following Class definition:
class PostObject
{
public string jsonrpc { get; set; }
public string method { get; set; }
public MyObject params { get; set; }
public string id { get; set; }
}
I use this class for a post call (serialized in json) and the server has 'params' as an input post var and there's no way to change it.
The question is that as params is a reserved keyword in c#, what should I do?
You can use serialization attributes to set it's name. Like this (NewtonSoft.Json):
[JsonProperty(PropertyName = "params")]
public MyObject parameters { get; set; }
Serialization Attributes in NewtonSoft.Json
Please see MSDN for the same. You can still use keywords as variable name but by appending '@'. Example :- int @int= 100;
Source,
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With