I've spent a good while this afternoon trying to implement the deserialization of JSON within a string, at first I was using DataContractJsonSerializer as my environment is Silverlight however it does not appear to support using a Dictionary out of the box (Raised in many other SO questions).
As an alternative I decided to use JSON.NET for the time being (Based on the answers to the aforementioned SO questions) and i've hit the following problem.
I want to deserialize the JSON below:
{
"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,
}
}
and place it within the following object (the double within the dictionary is required):
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; }
}
My latest attempt at actually getting this to work is below:
StreamReader reader = new StreamReader(args.Result);
ExchangeData data = JsonConvert.DeserializeObject<ExchangeData>(reader.ReadToEnd());
But this results in the following exception:
Could not load type 'System.Dynamic.IDynamicMetaObjectProvider' from assembly 'System.Core, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'.
Based on what you can see is my approach completely wrong or am I just making a schoolboy error (or both!)
Thanks for your time!