how to deserialize json to a dictionary or keyvaluepair? RRS feed

  • Question

  • I can't seem to find a good tutorial or example on deserializing a json file to a dictionary that works for me. I get a "arguementExeption was unhandled" error when reading the stream. I've read that it might be easier to deserialize to a keyvaluepair. dictionary or keyvaluepair would work fine for me but when I change "conversionRates" to a KeyValuePair, the key is read as null and value read as 0. unitTypeName gets read fine. Can anyone point me in the right direction?

    Here is are the properties of my class:

    public string unitTypeName { get; set; }

    public KeyValuePair conversionRates;

    Here is the json file I'm using:


    Here is the deserialization:

    DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(UnitResults));
    UnitResults results = (UnitResults)dataContractJsonSerializer.ReadObject(stream);
    Saturday, October 30, 2010 6:06 PM