我需要从这里获取 C# 中的货币值列表: http://openexchangerates.org/currencies.json
产生这种输出:
{
"AED": "United Arab Emirates Dirham",
"AFN": "Afghan Afghani",
"ALL": "Albanian Lek",
"AMD": "Armenian Dram",
"ANG": "Netherlands Antillean Guilder",
"AOA": "Angolan Kwanza"
// and so on
}
我设法使用 C# 获得了一个包含上述值的字符串,但我找不到将该字符串反序列化为任何自定义类或匿名对象的方法,所以我想知道该怎么做?
此外,我正在尝试使用 Json.NET 来做到这一点,但到目前为止找不到解决方案...
最佳答案
使用 Json.Net
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
--编辑--
你可以缩短它
WebClient w = new WebClient();
string url = "http://openexchangerates.org/currencies.json";
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(w.DownloadString(url));
关于c# - 如何将货币列表从 openexchangerates.org 反序列化为 C# 自定义类或对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523673/