我想序列化IDictionary中的项目,但是使用下面的代码会给我类似的错误
System.NotSupportedException: 'The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.'
下面是我的代码:
IDictionary<string, string> tmt = new Dictionary<string, string>();
tmt.Add("1", inf.Text);
XmlSerializer serializer = new XmlSerializer(typeof(Dictionary<string, string>));
StringWriter sw = new StringWriter();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(sw, tmt, ns);
inf.Text是我的文本框文本。
当我在
上运行代码时XmlSerializer serializer = new XmlSerializer(typeof(Dictionary<string, string>));
此行给了我上面提到的错误,我该如何解决该错误,或者还有另一种方法来进行序列化。
请帮助我
我希望将此Dictionary项作为关联数组