XML转List<T>
以上是我XML的数据
[Serializable]
public class Brand
{
[XmlAttribute("BrandID")]
public string BrandID { get; set; }
[XmlAttribute("GroupId")]
public string GroupId { get; set; }
[XmlAttribute("ShortName")]
public string ShortName { get; set; }
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("Letters")]
public string Letters { get; set; }
}
这是我实体类
List<Brand> list = XMLHelper.Deserialize<List<Brand>>(xml);
public static T Deserialize<T>(string xml)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(xml));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
object result = xs.Deserialize(memoryStream);
return (T)result;
}
运行报错XML 文档(2, 2)中有错误。。。。。小白请高手指点下XML转List<Brand>
------解决方案--------------------使用 LINQ 很方便面!
------解决方案--------------------