XML 문자열을 deserialize하려고했는데 객체를 deserialize하지 않습니다.XML 문자열을 역 직렬화하는 방법
내 XML 문자열은
같은<Cars>
<Car>
<Id>123445</Id>
<BMW>
<Id>78945</Id>
</BMW>
</Car>
</Cars>
[Serializable()]
[XmlRoot("Cars")]
public class Cars
{
[XmlArrayItem("Car",typeof(Car))]
public Car[] Car { get; set; }
}
[Serializable()]
public class Car
{
[XmlElement("Id")]
public long Id { get; set; }
[XmlArrayItem("BMW",typeof(BMW))]
public BMW[] BMW { get; set; }
}
[Serializable()]
public class BMW
{
[XmlElement("Id")]
public long Id { get; set; }
}
보이는 그리고 이것은 내가 노력하고 코드입니다 :
string str = "xml string like above";
XmlSerializer ser = new XmlSerializer(typeof(Cars));
var wrapper = (Cars) ser.Deserialize(new StringReader(str));
그리고 하위 배열의 몇 내부 BMW 같은 내부 객체 않아도됩니다. 차를 직렬화하지 않습니다. 누군가 내 실수를 지적 할 수 있습니까?
[Serializable()]
[XmlRoot("Cars")]
public class Cars
{
[XmlElement("Car",typeof(Car))]
public Car[] Car { get; set; }
}
[Serializable()]
public class Car
{
[XmlElement("Id")]
public long Id { get; set; }
[XmlElement("BMW",typeof(BMW))]
public BMW[] BMW { get; set; }
}
XML에 데이터가없는 빈 요소가있는이 문제가 있습니까? 아니면 오류 메시지가 나타 납니까? "차를 연재하지 않는다"는 것은 무엇을 의미합니까? 직렬화 또는 직렬화에 문제가 있습니까? –
오류 메시지가 무엇입니까? BMW의 정의는 어디에 있습니까? – SliverNinja
@SliverNinja : 오류 메시지가 없지만 개체에 요소가 없습니다. – alice7