Beispiel #1
0
        /// <summary>
        /// Json对象序列化
        /// </summary>
        /// <param name="obj">被序列化的对象</param>
        /// <param name="limitProps">属性限制设置</param>
        /// <param name="format">是否格式化</param>
        /// <returns></returns>
        public static string Serialize(object obj, LimitPropsContractResolver limitProps, bool format = false)
        {
            JsonSerializerSettings settings = _defaultSetting;

            if (limitProps != null)
            {
                settings.ContractResolver = limitProps;
            }
            return(Serialize(obj, settings, format));
        }
Beispiel #2
0
        /// <summary>
        /// Json对象反序列化
        /// </summary>
        /// <typeparam name="T">反序列化结果类型泛型</typeparam>
        /// <param name="jsonString">json字符串</param>
        /// <param name="limitProps">属性限制设置</param>
        /// <returns></returns>
        public static T Deserialize <T>(string jsonString, LimitPropsContractResolver limitProps)
        {
            JsonSerializerSettings settings = _defaultSetting;

            settings.Converters.RemoveType(typeof(IsoDateTimeConverter));
            if (limitProps != null)
            {
                settings.ContractResolver = limitProps;
            }
            return(Deserialize <T>(jsonString, settings));
        }
Beispiel #3
0
        /// <summary>
        /// Json对象序列化
        /// </summary>
        /// <param name="obj">被序列化的对象</param>
        /// <param name="format">是否格式化</param>
        /// <returns></returns>
        public static string Serialize(object obj, bool format = false)
        {
            LimitPropsContractResolver limitProps = null;

            return(Serialize(obj, limitProps, format));
        }
Beispiel #4
0
        /// <summary>
        /// Json对象反序列化
        /// </summary>
        /// <typeparam name="T">反序列化结果类型泛型</typeparam>
        /// <param name="jsonString">json字符串</param>
        /// <returns></returns>
        public static T Deserialize <T>(string jsonString)
        {
            LimitPropsContractResolver limitProps = null;

            return(Deserialize <T>(jsonString, limitProps));
        }