这是我的 xml 文件:<?xml version="1.0" encoding="utf-8"?><users> <user id="12"> <Nome>pedro</Nome> <Email>pedro.roldan@gmail.com</Email> <DataNascimento>1976-01-01</DataNascimento> <Foto>E:\Trabalho\web\12_7a639ffac9146d346372eb7598e1642f.jpg</Foto> </user> <user id="13"> <Nome>DORA</Nome> <Email>dora.bilro@gmail.com</Email> <DataNascimento>2003-02-12</DataNascimento> <Foto>E:\Trabalho\web\13_135bb70e258379ee643d575bd688a692.jpg</Foto> </user> <user id="14"> <Nome>dcdc</Nome> <Email>rui.moura@ff.pt</Email> <DataNascimento>1998-03-25</DataNascimento> <Foto>E:\Trabalho\web\14_7a639ffac9146d346372eb7598e1642f.jpg</Foto> </user></users>我试图在 asp.net mvc 中导入它。将其读入 ac# 列表的最佳方法是什么?提前致谢!
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
XmlSerializer serializer = new XmlSerializer(typeof(List<MyClass>));
using(FileStream stream = File.OpenWrite("filename"))
{
List<MyClass> list = new List<MyClass>();
serializer.Serialize(stream, list);
}
using(FileStream stream = File.OpenRead("filename"))
{
List<MyClass> dezerializedList = (List<MyClass>)serializer.Deserialize(stream);
}
- 1 回答
- 0 关注
- 147 浏览
添加回答
举报
0/150
提交
取消