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.

share|improve this question
    
Can you show a sample of exactly the JSON you're trying to parse? – Andrew Whitaker Apr 12 '15 at 13:21
    
Your answer ("use a Dictionary") is actually the accepted standard answer. You could answer your own question, if you want. – dbc Apr 12 '15 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.