zoukankan      html  css  js  c++  java
  • 序列化对象与反序列化对象

    序列化对象

    public string SerializeObject(object obj)
         {
             IFormatter formatter = new BinaryFormatter();
             string result = string.Empty;
             using (MemoryStream stream = new MemoryStream())
             {
                 formatter.Serialize(stream, obj);
                 byte[] byt = new byte[stream.Length];
                 byt = stream.ToArray();
                 result = Convert.ToBase64String(byt);
                 stream.Flush();
             }
             return result;
         }

    反序列化对象

    public object DeserializeObject(string str)
          {
              IFormatter formatter = new BinaryFormatter();
              byte[] byt = Convert.FromBase64String(str);
              object obj = null;
              using (Stream stream = new MemoryStream(byt, 0, byt.Length))
              {
                  obj = formatter.Deserialize(stream);
              }
              return obj;
          }

  • 相关阅读:
    Python:解析PDF文本及表格——pdfminer、tabula、pdfplumber 的用法及对比
    2018数学建模国赛B题
    目标检测综述整理
    numpy实现两层layer
    应用安全
    应用安全
    应用安全
    应用安全
    应用安全
    应用安全
  • 原文地址:https://www.cnblogs.com/HarryChis/p/10391008.html
Copyright © 2011-2022 走看看