• JsonHelper


    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;
    namespace MEAS.Common
    {
        public class JsonHelper
        {
            private static JsonHelper _jsonHelper = new JsonHelper();
            public static JsonHelper Instance { get { return _jsonHelper; } }
    
            public string Serialize(object obj)
            {
                return JsonConvert.SerializeObject(obj, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });
            }
            public string SerializeDateFormat(object obj)
            {
                return JsonConvert.SerializeObject(obj, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd" });
            }
            
    
            public string SerializeByConverter(object obj, params JsonConverter[] converters)
            {
                return JsonConvert.SerializeObject(obj, converters);
            }
    
            public T Deserialize<T>(string input)
            {
                return JsonConvert.DeserializeObject<T>(input, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
            }
    
            public T DeserializeByConverter<T>(string input, params JsonConverter[] converter)
            {
                return JsonConvert.DeserializeObject<T>(input, converter);
            }
    
            public T DeserializeBySetting<T>(string input, JsonSerializerSettings settings)
            {
                return JsonConvert.DeserializeObject<T>(input, settings);
            }
    
            private object NullToEmpty(object obj)
            {
                return null;
            }
        }
    }
    

      

  • 相关阅读:
    c/c++中两颗璀璨的明珠
    deepin软件中心打不开
    shell之rm -rf的别名设置
    历史命令脚本
    mysql之7xtrabackup
    python之3内置容器
    python之第一个例子hello world
    python之安装
    shell脚本练习(autocert)
    【转】nginx之逻辑运算
  • 原文地址:https://www.cnblogs.com/YYkun/p/16836598.html
Copyright © 2020-2023  润新知