string decodedPayLoad;
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
// Register the custom converter.
js.RegisterConverters(new JavaScriptConverter[] { new DictionaryConverter() });
IDictionary list = js.Deserialize<IDictionary>(decodedPayLoad);This is the custom class that was called above
public class DictionaryConverter : JavaScriptConverter
{
public override IEnumerable<Type> SupportedTypes
{
//Define the ListItemCollection as a supported type.
get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(IDictionary) })); }
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
throw new NotImplementedException();
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
if (dictionary == null)
throw new ArgumentNullException("dictionary");
return dictionary;
}
}
Hope it helps :)
No comments:
Post a Comment