如何序列化json.net的单个值
本文关键字:单个值 net json 序列化 | 更新日期: 2023-09-27 18:13:33
我正在使用json.net
序列化Student
类。
我想给序列化对象添加一个属性(称为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",
}
我想给序列化的对象添加属性" check ":
{
**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",
}
如果你需要能够反序列化和序列化对象,我将继承学生到一个新的类,像这样
public class StudentJson : Student
{
public bool cheak { get; set; }
}
你可以把它传递给序列化。