I had a good day trying to implement JSON deserialization inside a string, at first I used DataContractJsonSerializer , since my Silverlight environment, however, does not seem to support using Dictionary out of the box (raised in many other SO issues).
As an alternative, I decided to use JSON.NET for the moment (based on the answers to the above SO questions), and I applied the following problem.
I want to deserialize 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 put it in the following object (double dictionary 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 last attempt to actually get this to work below:
StreamReader reader = new StreamReader(args.Result);
ExchangeData data = JsonConvert.DeserializeObject<ExchangeData>(reader.ReadToEnd());
But this leads to the following exception:
'System.Dynamic.IDynamicMetaObjectProvider' 'System.Core, Version = 3.7.0.0, Culture = neutral, PublicKeyToken = 969DB8053D3322AC'.
, , ( , !)
!