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


            /// <summary>
            /// 序列化
            /// </summary>
            /// <param name="condition"></param>
            /// <returns></returns>
            [DebuggerStepThrough]
            public static string Serialize(this string target)
            {
                MemoryStream ms = new MemoryStream();
                BinaryFormatter br = new BinaryFormatter();
                br.Serialize(ms, target);
                byte[] resultbyte = ms.ToArray();
                string resultstr = Convert.ToBase64String(resultbyte, 0, resultbyte.Length);
                return resultstr.Replace("+", "%2B");
            }

            /// <summary>
            /// 反序列化
            /// </summary>
            /// <param name="condition"></param>
            /// <returns></returns>
            [DebuggerStepThrough]
            public static string Deserialize(this string target)
            {
                var str = target.Replace("%2B", "+");
                byte[] bb = Convert.FromBase64String(str);
                MemoryStream ms = new MemoryStream(bb);
                BinaryFormatter br = new BinaryFormatter();
                object o = br.Deserialize(ms);

                ms.Flush();
                return o.ToString();
            }
  • 相关阅读:
    TF利用分布式队列控制线程
    非随机的抽样
    代码杂谈-split函数
    beta函数与置信度估计
    tensorflow模型
    SQL的技巧
    tensorflow输入数据处理
    flink学习
    Python
    通过淘宝IP地址库获取IP位置
  • 原文地址:https://www.cnblogs.com/roamman/p/1625480.html
Copyright © 2011-2022 走看看