作为替代方案,我决定暂时使用JSON.NET(根据前面提到的SO问题的答案),但我遇到了以下问题。
我想反序列化下面的JSON:
{
"disclaimer": "This data is collected from various providers and provided free of charge for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability or fitness for any purpose; use at your own risk. Other than that - have fun, and please share/watch/fork if you think data like this should be free!",
"license": "Data collected from various providers with public-facing APIs; copyright may apply; not for resale; no warranties given.",
"timestamp": 1334183999,
"base": "USD",
"rates": {
"AED": 3.6732,
"AFN": 48.400002,
"ALL": 106.669998,
}
}
将其放置在以下对象中(字典内的两个双引号是必需的):
public class ExchangeData
{
public string disclaimer { get; set; }
public string license { get; set; }
public string timestamp { get; set; }
public string @base { get; set; }
public Dictionary<string, double> rates { get; set; }
}
我最新的尝试是以下代码:
StreamReader reader = new StreamReader(args.Result);
ExchangeData data = JsonConvert.DeserializeObject<ExchangeData>(reader.ReadToEnd());
但是这会导致以下异常:
无法从程序集'System.Core, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'中加载类型'System.Dynamic.IDynamicMetaObjectProvider'。
根据您所看到的,我的方法完全错误还是我只是犯了一个低级错误(或两者都有!)
感谢您的时间!