C# 对象转JSON字符串

对象转JSON字符串

/// <summary>
        /// 对象转Json字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="isCamel"></param>
        /// <returns></returns>
        public static string ToJsonString(object obj, bool isCamel = false)
        {
            var settings = new JsonSerializerSettings
            {
                DateFormatString = "yyyy-MM-dd HH:mm:ss",
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
            if (isCamel)
            {
                settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }
            return JsonConvert.SerializeObject(obj, settings);
        }

 

C# 对象转JSON字符串

上一篇:WPF 获取鼠标屏幕位置、窗口位置、控件位置


下一篇:windows10打开switchHost,提示无修改权限