我正在尝试Hashtable
用 ServiceStack序列化一个JsonSerializer
。然而,与 Json.Net 和 built-in 不同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"]
难道我做错了什么?