. use different encoding" /> . use different encoding - 秒客网" />

. use different encoding

时间:2023-11-21 12:48:56
public string Serialize<T>(T serializeClass)
{
string xmlString = string.Empty;
try
{
if (serializeClass != null)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
StringBuilder xmlStringBuilder = new StringBuilder();
XmlWriterSettings setting = new XmlWriterSettings() { Encoding = Encoding.UTF8}; using (XmlWriter writer = XmlWriter.Create(xmlStringBuilder, setting))
{
serializer.Serialize(writer, serializeClass);
xmlString = xmlStringBuilder.ToString();
}
}
}
catch (Exception ex)
{
xmlString = string.Empty;
}
return xmlString;
}