When deserializing the following json response I manage to get the subscribers id, e-mail and status, which is easy as these names are always the same and are not dependent on the particular settings in a list. But how can I deserialize the merge-fields and the interests that do have different names in different lists?
{ "members": [ {
"id": "f777bbffab8d1ceca8b757df63c47cb8",
"email_address": "urist.mcvankab+1@freddiesjokes.co",
"unique_email_id": "882e9bec19",
"status": "subscribed",
"merge_fields":{
"FNAME": "",
"LNAME": "" },
"interests":{
"9143cf3bd1": true,
"3a2a927344": false,
"f9c8f5f0ff": false,
"f231b09abc": true,
"bd6e66465f": false },
//And so on...
How can I change my classes to deserialize the response?
My Member Class
public class Member
{
public string id { get; set; }
public string email_address { get; set; }
public string status { get; set; }
//public List<MergeField> mergeFields { get; set; }
//public List<Interests> interests { get; set; }
}
Where the MergeField refers to to my old MergeField class, where the fields were hardcoded
public class MergeField
{
public string FNAME { get; set; }
public string LNAME { get; set; }
public string ADDRESS { get; set; }
public string MERGE4 { get; set; }
}
But I would like to use the same two Mergefield(s) classes that I use to deserialize the json response when requesting a list's merge-fields.
public class MergeFields
{
public List<Mergefield> merge_fields { get; set; }
public string list_id { get; set; }
public int total_items { get; set; }
}
public class Mergefield
{
public string merge_id { get; set; }
public string tag { get; set; }
public string name { get; set; }
public string list_id { get; set; }
}
I found this answer How do deserialize JSON with non-standard (and varying) property names, but I cannot figure out how to use it in my scenarío.