Ignoring a field during .NET JSON serialization; similar to [XmlIgnore]?

后端 未结 4 723
鱼传尺愫
鱼传尺愫 2020-11-30 05:38

I have a POCO class that is being sent to the browser as a JSON string in .NET 3.5 sp1. I am just using the default JSON serialization and I have some fields that I want to

4条回答
  •  死守一世寂寞
    2020-11-30 06:00

    I use the ScriptIgnore attribute on my model like so:

    public class Item
    {
        [ScriptIgnore]
        public Item ParentItem { get; set; }
    }
    

    In this particular scenario I was getting a circular reference error from the Json serializer, so I simply ignored it. I was asking a similar question here on SO when I was turned on to the difference between a Model and ViewModel.

提交回复
热议问题