c#序列化和反序列化list

List<UserData> lstStuModel = new List<UserData>()
{
new UserData(){Name="001",Email="001@w.c",Password="888888"},
new UserData(){Name="002",Email="002@w.c",Password="188888"}
};

//Json.NET序列化
string jsonData = JsonConvert.SerializeObject(lstStuModel);

//[{"Name":"001","Password":"888888","Email":"001@w.c"},{"Name":"002","Password":"188888","Email":"002@w.c"}]


//Json.NET反序列化
string json = jsonData;
List< UserData> descJsonStu = JsonConvert.DeserializeObject<List<UserData>>(json);//反序列化

//反序列化单个对象

UserData userData = JsonConvert.DeserializeObject<UserData>(json)

 

posted @ 2017-09-19 13:07  jiftle  阅读(4479)  评论(0编辑  收藏  举报