My API Response json has below fields when I paste JSON as classes it created the one of the field as _class as class is a reserved keyword
- Actual
public class Imp
{
public string Name { get; set; }
**public string _class { get; set; }**
public Address address { get; set; }
public decimal highest { get; set; }
}
but my requirement is to have field as class only, Could anyone suggest how to achieve this?
- Desired
public class Imp
{
public string Name { get; set; }
public string class { get; set; }
public Address address { get; set; }
public decimal highest { get; set; }
}
>Solution :
public string @class {get;set;}
However, convention would be to call it Class instead, in which case: no problem in the first place. If serialization is the problem, most serializers have attributes to help with that:
[JsonProperty("class")]
public string Class {get;set;}
(or whatever your serializer uses)