How to mark a property as non serializable for json?

前端 未结 3 1838
悲哀的现实
悲哀的现实 2021-02-07 07:44

As the title says, I want to mark a property as non serializable by the JavascriptSerializer. How can achive that ? Thanks in advance.

3条回答
  •  忘了有多久
    2021-02-07 08:08

    As of .NET 3.0, you can use DataContract instead of Serializable. With the DataContract though, you will need to either "opt-in" by marking the serializable fields with the DataMember attribute; or "opt-out" using the IgnoreDataMember.

    The main difference between opt-in vs opt-out is that opt-out by default will only serialize public members, while opt-in will only serialize the marked members (regardless of protection level).

    Note that if you are using Newtonsoft.Json for your serialization (like in my case), it supports DataContract as well.

提交回复
热议问题