Musakkhir Sayyed Musakkhir Sayyed - 4 months ago 9
JSON Question

How do I add `+` to a property name in C#?

How do I declare a property or variable name as

fg+
in C#?

public string fg+ { get; set; }


I am getting
fg+
as a field in a response from JSON as
"fg+": "103308076644479658279"
.

I am deserializing it using a class. How do I read it from JSON?

Answer

Such a variable name isn't legal in C#.

If you're using Json.NET to deserialize your data, you can use the JsonProperty attribute to give it a custom name:

[JsonProperty("fg+")]
public string Fg { get; set; }
Comments