测试代码

2016-08-09  本文已影响0人  沉睡的木木夕

三级标题

public class JsonHelper
    {
        public static string SerializerObject(object entity)
        {
            if (entity == null)
                return string.Empty;
            return JsonConvert.SerializeObject(entity);
        }

        public static string SerializerObject(object entity, JsonDynamicContractResolver jsonDynamicContractResolver)
        {
            if (entity == null)
                return string.Empty;
            return JsonConvert.SerializeObject(entity, Formatting.Indented, new JsonSerializerSettings()
            {
                ContractResolver = jsonDynamicContractResolver
            });
        }

        public static string Serializer<T>(T entity) where T : class
        {
            if (entity == null)
                return string.Empty;
            return JsonConvert.SerializeObject(entity);
        }

        public static string Serializer<T>(T entity, JsonDynamicContractResolver jsonDynamicContractResolver) {
            if (entity == null)
                return string.Empty;
            return JsonConvert.SerializeObject(entity, Formatting.Indented, new JsonSerializerSettings() { 
                ContractResolver = jsonDynamicContractResolver
            });
        }

        public static T Deserializer<T>(string json) where T : class,new() {
            if (String.IsNullOrEmpty(json))
                return new T();
            return (T)JsonConvert.DeserializeObject<T>(json);
        }

        public static T DeserializerAnonymous<T>(string json,T anonymousObj){
            if (String.IsNullOrEmpty(json))
                throw new ArgumentNullException("json格式不正确且不能为空");
            return (T)JsonConvert.DeserializeAnonymousType(json, anonymousObj);
        }


        //internal enum JsonFormat
        //{
        //    None = 0,
        //    Indented = 1,
        //}

        //internal class JsonSerializerSetting {
        //    public static JsonDynamicContractResolver JsonDynamicContractResolver { get { return } }
        //}
    }
  1. 有序列表1
  2. 有序列表2

博客园

引用:没有什么是钱是搞不定的,如果有,那就是钱不够 ——来自沉睡的木木夕

这是卸体
这是粗体

<p>这是段落</p>

Tables Area Cool
默认左对齐 居中 右对齐
上一篇下一篇

猜你喜欢

热点阅读