private void Form6_Load(object sender, EventArgs e) { stud1 objstud1 = new stud1() { id = 100, sex = "男", birthday = new DateTime(1972, 5, 29),fname="zhang" }; string str= Newtonsoft.Json.JsonConvert.SerializeObject(objstud1); stud0 objstu0 = Newtonsoft.Json.JsonConvert.DeserializeObject<stud0>(str) ; //正确返回 stud2 objstu2 = Newtonsoft.Json.JsonConvert.DeserializeObject<stud2>(str); //正确返回 stud2 objstu3 = Newtonsoft.Json.JsonConvert.DeserializeObject(str) as stud2; //返回null } public class stud0 { public int id; public string sex; } public class stud1 { public int id; public string sex; public DateTime birthday; public string fname; } public class stud2 { public int id; public string sex; public DateTime birthday; public string mname; }
时间: 2024-10-06 22:49:03