Newtonsoft.Json serialization returns empty json object

后端 未结 4 1428
轻奢々
轻奢々 2020-12-25 10:09

I have list of objects of following class:

public class Catagory
{
    int catagoryId;
    string catagoryNameHindi;
    string catagoryNameEnglish;
    List         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-25 10:33

    You could also decorate your class to serialize all members you want without having to specify [JsonProperty] for each of them.

    [JsonObject(MemberSerialization.OptOut)]
    public class Catagory {
        ...
    }
    

    The MemberSerialization enum allows you to specify what members you want to serialize:

    • MemberSerialization.OptOut: All public members are serialized.
    • MemberSerialization.OptIn: Only members marked with JsonPropertyAttribute or DataMemberAttribute are serialized.
    • MemberSerialization.Fields: All public and private members are serialized.

提交回复
热议问题