我正在尝试使用ServiceStack Hashtable
序列化JsonSerializer
。但是,与Json.Net和内置JavaScriptSerializer
不同,它返回DictionaryEntry
的类型名称而不是值。
此代码:
Hashtable h = new Hashtable(){ { "A", 1 }, { "B", 2 } };
Console.WriteLine(JsonConvert.SerializeObject(h));
Console.WriteLine(new JavaScriptSerializer().Serialize(h));
Console.WriteLine(ServiceStack.Text.JsonSerializer.SerializeToString(h, typeof(Hashtable)));
返回:
{"A":1,"B":2}
{"A":1,"B":2}
["System.Collections.DictionaryEntry","System.Collections.DictionaryEntry"]
我做错了吗?