我正在尝试使用C#中的API,有问题的数据如下所示:
"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"
当使用我认识的方法时,在C#类中看起来像这样:
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; }
}
但是,出于显而易见的原因,我希望它是:
public class RootObject
{
public list<Currency> supported_cct { get; set; }
}
public class Currency
{
public string threeletter { get; set; }
public string fullname { get; set; }
}
目前我正在尝试使用NetonSoft JSON来执行此操作:
JsonConvert.DeserializeObject<MySelf>(result.Content.ReadAsStringAsync().Result);
编辑:
找到一个解决方案,而不是使用在我的用例中工作的词典,但如果这对其他人不起作用,那么很高兴看到另一个答案。