1

I am consuming a simple REST API. The way I usually do this from my .Net environment is to use a HttpClient and just use Newstonsoft JSON.NET to deserialize the JSON response back into a class I have created.

I usually just create my variables with the same name as the JSON variable so it can map and be deserialized correctly.

However the variables in the current API I am consuming just do not make that much sense so I am wondering if it is at possible to have something like the below so that I can name my class variables correctly but still have the deserialization map back.

[Serializable(Name="param1")]
public string CompanyName { get; set; }
SashaStojanovic
  • 331
  • 3
  • 15

1 Answers1

2

Use:

[JsonProperty("param1")]
public string CompanyName {get; set;}

Or:

[JsonProperty(PropertyName="param1")]
public string CompanyName {get; set;}
stephanV
  • 183
  • 6