public JsonSerializer() { this._referenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Error; this._missingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore; this._nullValueHandling = Newtonsoft.Json.NullValueHandling.Include; this._defaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include; this._objectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Auto; this._preserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; this._constructorHandling = Newtonsoft.Json.ConstructorHandling.Default; this._typeNameHandling = Newtonsoft.Json.TypeNameHandling.None; this._context = JsonSerializerSettings.DefaultContext; this._binder = DefaultSerializationBinder.Instance; }
/// <summary> /// 将对象序列化为JSON字符串,循环引用的对象将被忽略 /// </summary> /// <param name="value"></param> /// <param name="formatting"></param> /// <param name="settings"></param> /// <param name="nullValue"></param> /// <param name="referenceLoop"></param> /// <returns></returns> public static string ToJson(this object value, Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.None, Newtonsoft.Json.NullValueHandling nullValue = Newtonsoft.Json.NullValueHandling.Ignore, Newtonsoft.Json.ReferenceLoopHandling referenceLoop = Newtonsoft.Json.ReferenceLoopHandling.Ignore, Newtonsoft.Json.JsonSerializerSettings settings = null) { if (settings == null) { settings = new Newtonsoft.Json.JsonSerializerSettings() { ReferenceLoopHandling = referenceLoop, // 忽略循环引用 NullValueHandling = nullValue, }; } var json = Newtonsoft.Json.JsonConvert.SerializeObject(value, formatting, settings); return(json); }
public JsonSerializer() { Class6.yDnXvgqzyB5jw(); base(); this._referenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Error; this._missingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore; this._nullValueHandling = Newtonsoft.Json.NullValueHandling.Include; this._defaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include; this._objectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Auto; this._preserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; this._constructorHandling = Newtonsoft.Json.ConstructorHandling.Default; this._typeNameHandling = Newtonsoft.Json.TypeNameHandling.None; this._metadataPropertyHandling = Newtonsoft.Json.MetadataPropertyHandling.Default; this._context = JsonSerializerSettings.DefaultContext; this._serializationBinder = DefaultSerializationBinder.Instance; this._culture = JsonSerializerSettings.DefaultCulture; this._contractResolver = DefaultContractResolver.Instance; }