• Josn序列化与反序列化


      using System.Web.Script.Serialization;

    /// <summary>
            /// 序列化器
            /// </summary>
            private static readonly JavaScriptSerializer serializer;

            /// <summary>
            /// 构造函数
            /// </summary>
            static SlJson()
            {
                serializer = new JavaScriptSerializer();
                serializer.MaxJsonLength = int.MaxValue;
                serializer.RecursionLimit = int.MaxValue;
            }

    /// <summary>
            /// 将对象序列化为Json格式的字符串
            /// </summary>
            /// <param name="source">源类型对象</param>
            /// <returns>Json格式的字符串</returns>
            public static string ToJson(object source)
            {
                return serializer.Serialize(source);
            }

      /// <summary>
            /// 将Json格式的数据转换为对象
            /// </summary>
            /// <typeparam name="T">源类型</typeparam>
            /// <param name="json">json格式的字符串</param>
            /// <returns>序列化之后的格式</returns>
            public static T FromJson<T>(string json)
            {
                return serializer.Deserialize<T>(json);
            }

  • 相关阅读:
    DFS
    关于memset

    SpringCloud(六)Ribbon负载均衡
    每日算法练习(2020-1-27)
    SpringCloud(五)Eureka Server高可用集群与常见问题
    SpringCloud(四)Eureka服务注册与发现
    SpringCloud(三)常用系统架构技术讲解
    Redis(八)
    Redis(七)
  • 原文地址:https://www.cnblogs.com/sk2016/p/6090203.html
Copyright © 2020-2023  润新知