zoukankan      html  css  js  c++  java
  • 序列化 对象 不需要创建文件的方法?

                UserProfile profile = new UserProfile();

                XmlSerializer serializer = new XmlSerializer(typeof(UserProfile));
                MemoryStream ms = new MemoryStream();
                using(TextWriter w = new StreamWriter( ms,System.Text.Encoding.UTF8 ))
                {
                    serializer.Serialize(ms,profile);
                }

                string xml=System.Text.Encoding.UTF8.GetString(ms.ToArray());

       XmlSerializer serializer = new XmlSerializer(typeof(ListItems));
                           XmlDocument doc = new XmlDocument();
                           const string root = @"<?xml version=""1.0""?>";
                           string xmlContent = root + HttpUtility.HtmlDecode(strExtend);
                           doc.LoadXml(xmlContent);
                           System.IO.MemoryStream stream = new System.IO.MemoryStream();
                           doc.Save(stream);
                           stream.Seek(0, SeekOrigin.Begin);
                           XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
                           xmlns.Add(String.Empty, String.Empty);
                           ListItems  m_ItemList = serializer.Deserialize(stream) as ListItems;

       XmlSerializer serializer = new XmlSerializer(typeof(List<Option>));
                        string strContent = myRow["Options"].ToString();
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(strContent.TrimEnd('?'));
                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        doc.Save(stream);
                        stream.Seek(0, SeekOrigin.Begin);

                        List<Option> myList = serializer.Deserialize(stream) as List<Option>;

     

  • 相关阅读:
    浅析VO、DTO、DO、PO的概念、区别和用处
    serialVersionUID的作用
    Eclipse Debug提示source not found解决方案
    eclipse的块选择模式
    Java工程Properties配置文件注释中文,会自动转换为其他编码方式问题解决 中文乱码
    spring boot1.5以上版本@ConfigurationProperties取消location注解后的替代方案 cannot resolve method location
    c++11多线程
    多媒体指令(AVX加速数组求和)
    oracle数据库occi接口写入中文乱码解决方法
    c++得到窗口句柄
  • 原文地址:https://www.cnblogs.com/DotNet1010/p/1145471.html
Copyright © 2011-2022 走看看