List到XML的序列化与反序列化

原文 http://hi.baidu.com/shishengli1234/item/f0536f36335390c22f8ec24b

Model.RESE_SCH sch1 = new Model.RESE_SCH();
sch1.CLINIC_TIME = DateTime.Now.AddDays(1);
sch1.EXPERT_NO = "1";
sch1.REG_TYPE = "1";
sch1.RSRC_ID = "1";
sch1.SERIAL_NO = "22";
sch1.UUID = "1"; Model.RESE_SCH sch2 = new Model.RESE_SCH();
sch2.CLINIC_TIME = DateTime.Now.AddDays(2);
sch2.EXPERT_NO = "1";
sch2.REG_TYPE = "1";
sch2.RSRC_ID = "1";
sch2.SERIAL_NO = "22";
sch2.UUID = "1"; List<Model.RESE_SCH> reseList = new List<Model.RESE_SCH>();
reseList.Add(sch1);
reseList.Add(sch2); XmlSerializer ser = new XmlSerializer(typeof(List<Model.RESE_SCH>));
System.IO.MemoryStream mem = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(mem, Encoding.Default);
ser.Serialize(writer, reseList);
writer.Close(); string strtmp = Encoding.Default.GetString(mem.ToArray()); //反序列化
StreamReader sr = new StreamReader("文件路径");//定义流将xml读出来
var listsch = ser.Deserialize(sr);//反序列化成object
List<Model.RESE_SCH> reses = listsch as List<Model.RESE_SCH>;
上一篇:正则表达式中的\n


下一篇:Android开发之获取状态栏高度、屏幕的宽和高