Newtonsoft.Json 序列化反序列化

时间:2021-06-04 22:50:46

public class People
{
public string name { get; set; }
public string age { get; set; }
public string sex { get; set; }
}
List<People> list = new List<People>();
list.Add(new People { name = "Jane", age = "18", sex = "female" });
list.Add(new People { name = "Lucy", age = "21", sex = "female" });
list.Add(new People { name = "Anne", age = "20", sex = "female" });

string str = JsonConvert.SerializeObject(list);//序列化
List<People> peopleList = JsonConvert.DeserializeObject<List<People>>(str);//反序列化