Categories
Mastering Development

C# Deserialize Two Jarray Objects in Single Object

I have an external API that returns the response in this format:

Headers: {[
  [
    {"displayName": "First Name"},
    {"displayName": "Last Name","field": "FieldName2Formula"},
    {"displayName": "Age","field": "FieldName3Formula"}
  ]
]},
Data:{[
  [
    "John",
    "Smith",
    "50"
  ],
  [
    "Liam",
    "Miller",
    "10"
  ]
]}

I have a Class where i want the API Response to be deserialized to

Class1.cs

[JsonProperty("First Name")]
public string FirstName { get; set; }

[JsonProperty("Last Name")]
public string LastName { get; set; }

public int Age { get; set; }

My question is how I can deserialize the response into this class given the structure of the API Response I have?

I tried to create a class called APIResponse.cs and map the Headers and Data into JArray:

    public JArray Data { get; set; }
    public JArray Headers { get; set; }

Any thoughts? Appreciate your help.

Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *