I am trying to consume an API in C#, the data in question looks like this:
"MXN": "Mexican Peso",
"MYR": "Malaysian Ringgit",
"NOK": "Norwegian Krone",
"NZD": "New Zealand Dollar",
"PLN": "Zloty",
"RUB": "Russian Ruble",
"SEK": "Swedish Krona",
"SGD": "Singapore Dollar",
"USD": "US Dollar",
"VUV": "Vatu",
"XTN": "Bitcoin Testnet",
"ZAR": "Rand"
Which, when using the method I am aware of looks like this in C# classes:
public class SupportedCct
{
//obvious pattern
public string USD { get; set; }
public string VUV { get; set; }
public string XTN { get; set; }
public string ZAR { get; set; }
}
public class RootObject
{
public SupportedCct supported_cct { get; set; }
}
However, for obvious reasons I would prefer it to be:
public class RootObject
{
public list<Currency> supported_cct { get; set; }
}
public class Currency
{
public string threeletter { get; set; }
public string fullname { get; set; }
}
Currently I am trying to use NetonSoft JSON to do this:
JsonConvert.DeserializeObject<MySelf>(result.Content.ReadAsStringAsync().Result);
EDIT:
Found one solution, which is instead to use a Dictionary which works in my use case, but would be great to see another answer in case this won't work for someone else.