碰到Java序列化出来奇怪xml如:
<User>
<Friend>张三</Friend>
<Friend>张三</Friend>
<Friend>张三</Friend>
</User>
奇怪的是,Friend是一个数组,但并没有父元素,这种情况 如果反序列化?
[Serializable]
public class User
{
public Friend[] Friend { get; set; }
}
是不行的。
正确方法:
[Serializable]
public class User
{
[XmlElement]
public Friend[] Friend{ get; set; }
}
还好是用XMLSerializer, 如果使用DataContractSerializer, 应该是不行的。