I am trying to serialize a Dictionary to JSON, and get the following exception:
new JavaScriptSerializer().Serialize(mydict)`
Ty
The blog http://dukelupus.wordpress.com/2011/05/04/asp-net-mvc-json-and-a-generic-dictionary/ describes an extension method Dictionary ToJsonDictionary(this Dictionary input)
use NewtonSoft.Json instead of JavaScriptSerializer to overcome this problem:
Ex:
JsonConvert.SerializeObject(mydict);
var dict = mapping.ToDictionary(item => item.Key.ToString(), item => item.Value.ToString());`
that will convert any Dictionary<K,V> to Dictionary<string,string> and serialization then works.