Thinkai's Blog

Autohoutkey|Python|php|aardio|VOIP|IT 爱好者

xml 序列化和反序列化 C# 448

作者为 发表

编程

//把object序列化成xml字符串

public string Serialize(Type type,Object o)

{

    MemoryStream ms = new MemoryStream();

    XmlSerializer xmlserializer = new XmlSerializer(type);

    xmlserializer.Serialize(ms, o);

    StreamReader reader = new StreamReader(ms);

    return reader.ReadToEnd();

}


//把xml字符串反序列化成object

public Object Deserialize(Type type, string xmlstr)

{

    byte[] xmlArray = System.Text.Encoding.UTF8.GetBytes(xmlstr);

    MemoryStream ms = new MemoryStream(xmlArray);

    XmlSerializer xmlserializer = new XmlSerializer(type);

    return xmlserializer.Deserialize(ms);

}



来了就留个评论吧! 没有评论




友情链接:Autohotkey中文论坛Autohotkey中文帮助Autohotkey官网我的B站直播间如若生涯一场梦博客联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

65 queries in 0.620 seconds |