首页 > 代码库 > XML序列化
XML序列化
XmlSerializer xmlSer = new XmlSerializer(typeof(Class1));MemoryStream writer = new MemoryStream();Class1 c2 = new Class1();c2.b = "123";c2.c = 333;c2.cc = new Class2[2];c2.cc[0] = new Class2();c2.cc[0].bb = 223;c2.cc[1] = new Class2();c2.cc[1].bb = 555;xmlSer.Serialize(writer, c2);StreamReader sr = new StreamReader(writer);var str = Encoding.UTF8.GetString(writer.ToArray());Console.WriteLine(str);Console.ReadLine();writer.Flush();writer.Close();
反序列化
XmlSerializer serializer = new XmlSerializer(typeof(Class1));TextReader reader = new StringReader(str);Class1 c1 = (Class1)serializer.Deserialize(reader);
XML序列化
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。