Tuesday, January 27, 2009 6:14 AMI'm trying to use DataContractJsonSerializer to deserialize a JSON string, that looks like:
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Dictionary<string, object>));
The output for this is always an empty dictionary with no exceptions.
My question is what should the type parameter be in the constructor? I've noticed that there's another constructor that asks for a knownTypes, could I have perhaps need to put a list of int and bool for what's in the object array? I'm kinda puzzled of what's wrong with this. Please help!
Tuesday, January 27, 2009 6:53 AM
Dictionaries are serialized in JSONas arrays of KeyValuePair<K, V> - since one can use types other than strings as the key in CLR, it doesn't map directly to a JSON Object.
To read an arbitrary JSON object into a dictionary using the DataContractJsonSerializer, you can use an ISerializable type:
- Proposed As Answer by Carlos Figueira Wednesday, January 28, 2009 8:20 PM
Wednesday, February 22, 2012 8:32 AM
This solution doesn't work for Silverlight, since Silverlight doesn't support the Serializable attribute or the ISerializeable interface. Is there a way to read arbitrary JSON in to an IDictionary<string,object> using DataContractJsonSerializer from Silverlight?