<?xml version="1.0" encoding="utf-16"?>. use different encoding

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; }

 

posted @ 2013-11-07 15:10  Vincent.Dr  阅读(757)  评论(0编辑  收藏  举报