JsonConvert.SerializeObject序列化对象,对象里面含有虚方法的时候,怎么过滤?

fsb1582813 2015-11-23 09:47:35
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; }
}
...全文
1742 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
byronqiji 2015-11-23
  • 打赏
  • 举报
回复
对不需要实例化的属性添加[NonSerialized]属性
fsb1582813 2015-11-23
  • 打赏
  • 举报
回复
终于解决了,this.Configuration.LazyLoadingEnabled = true; this.Configuration.ProxyCreationEnabled = false;//加了这一句

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧