Thinkai's Blog

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

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

作者为 发表

编程

//把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);

}



来了就留个评论吧! 1个评论




友情链接:Autohotkey中文帮助Autohotkey官网Autohotkey中文网联系作者免GooglePlay APK下载

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

65 queries in 1.784 seconds |