In NewtonSoft JSON, how to use object names as variables in object rather than as individual objects.

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 NewtonSoft JSON to do this:


by williamdunne via /r/csharp

Leave a Reply