JsonConvert.SerializeObject序列化对象,对象里面含有虚方法的时候,怎么过滤?
JsonConvert.SerializeObject序列化时候,报错,出现了死循环,
我的方法:
JsonSerializerSettings MyJsonSerializerSettings = new JsonSerializerSettings();
MyJsonSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
IsoDateTimeConverter dateTimeConverter = new IsoDateTimeConverter();
dateTimeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
MyJsonSerializerSettings.Converters.Add(dateTimeConverter);
return Content(JsonConvert.SerializeObject(date, Formatting.Indented, MyJsonSerializerSettings));
我的实体类:
public partial class Customers
{
public Customers()
{
this.Shop_Coupons = new HashSet<Shop_Coupons>();
this.PointValueRecords = new HashSet<PointValueRecords>();
this.shop_MakeComplaints = new HashSet<shop_MakeComplaints>();
this.Shop_SaleOrders = new HashSet<Shop_SaleOrders>();
this.Shop_ShoppingCarts = new HashSet<Shop_ShoppingCarts>();
}
public int Id { get; set; }
public string UserName { get; set; }
public string NickName { get; set; }
public string Email { get; set; }
public string Tel { get; set; }
public string PwdLogin { get; set; }
public string PwdPay { get; set; }
public Nullable<int> SecurityLevel { get; set; }
public System.DateTime RegisterDate { get; set; }
public bool Enabled { get; set; }
public Nullable<int> Member { get; set; }
public Nullable<bool> Sex { get; set; }
public string Profession { get; set; }
public string Education { get; set; }
public string Birthday { get; set; }
public string Adress { get; set; }
public Nullable<int> ProvinceID { get; set; }
public Nullable<int> CityID { get; set; }
public Nullable<int> DistrictId { get; set; }
public string HeadImgUrl { get; set; }
public virtual CustomerEpds CustomerEpds { get; set; }
public virtual ICollection<Shop_Coupons> Shop_Coupons { get; set; }
public virtual ICollection<PointValueRecords> PointValueRecords { get; set; }
public virtual ICollection<shop_MakeComplaints> shop_MakeComplaints { get; set; }
public virtual ICollection<Shop_SaleOrders> Shop_SaleOrders { get; set; }
public virtual ICollection<Shop_ShoppingCarts> Shop_ShoppingCarts { get; set; }
}