0

我正在Student使用json.net.

我想向序列化对象添加一个属性(称为cheak不是Student该类的成员。

这是班级学生:

public class Student 
    {
        public int ID { get; set; }
        [JsonIgnore]
        public Faculty Faculty { get; set; }
        [JsonProperty("Faculty")]
        public string FacultyName { get { return Faculty.name; } }
        public double AVG { get; set; }
        public DateTime DateOfBirth { get; set; }
        public string EducationInfo { get; set; }
        public string FatherName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string MotherName { get; set; }
        public string Password { get; set; }
        public string PersonalInfo { get; set; }
    }

json:

{
  "ID": 24,
  "Faculty": "engen ",
  "AVG": 3.0,
  "DateOfBirth": "1990-02-02T00:00:00",
  "EducationInfo": "GOOD",
  "FatherName": "EEWF",
  "FirstName": "FFEWR",
  "LastName": "ERF",
  "MotherName": "ERF",
  "Password": null,
  "PersonalInfo": "ERF",
}

我想将属性“cheak”添加到序列化对象中:

{
  **cheak:true
  "ID": 24,
  "Faculty": "engen ",
  "AVG": 3.0,
  "DateOfBirth": "1990-02-02T00:00:00",
  "EducationInfo": "GOOD",
  "FatherName": "EEWF",
  "FirstName": "FFEWR",
  "LastName": "ERF",
  "MotherName": "ERF",
  "Password": null,
  "PersonalInfo": "ERF",
}
4

1 回答 1

0

如果您需要能够反序列化和序列化对象,我会将学生继承到这样的新类

public class StudentJson : Student 
{
    public bool cheak { get; set; }
}

然后,您可以将其传递给序列化。

于 2013-05-14T12:43:29.560 回答