我用于反序列化的 XML 字符串
> <?xml version="1.0" encoding="utf-16"?> <ReceiveAccountSetting
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <POP3>POP3</POP3>
> <Server>webmail.in</Server>
> <AccountId>vivek.s@gmail.com</AccountId> <Password>123</Password>
> <EnableSSL>true</EnableSSL> <DefaultPort>25</DefaultPort>
> </ReceiveAccountSetting>
当尝试反序列化时,它会给出错误“ XML 文档 (0, 0) 中存在错误”
我的课
public class ReceiveAccountSetting
{
/// <summary>
/// Receiving Email
/// </summary>
//public int AccountType { get; set; }
public string POP3 { get; set; }
public string IMAP { get; set; }
public string Server { get; set; }
public string AccountId { get; set; }
public string Password { get; set; }
public bool EnableSSL { get; set; }
public int DefaultPort { get; set; }
}
脱硫方法
public EmailAccount Deserialize(string xmlstring)
{
EmailAccount objEmail = new EmailAccount();
XmlSerializer serializer = new XmlSerializer(typeof(EmailAccount));
StringReader reader = new StringReader(xmlstring);
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlstring)))
{
objEmail = (EmailAccount)serializer.Deserialize(stream);
}
objEmail = (EmailAccount)serializer.Deserialize(reader);
return objEmail;
}