0
我试图反序列化对象又包含其他对象的名单列表的列表对象的列表。我得到的是以下内容。 实际的反序列化是由ApiContoller httpPost请求中的框架完成的。端点看起来是这样的:XML反序列化对象包含在C#
[HttpPost]
public async Task<HttpResponseMessage> MethodCall([FromBody] XmlEntries entries)
{
....
}
的XmlEntries类看起来是这样的:
[XmlRoot("Root")]
public class XmlEntries
{
[XmlArrayItem("XmlEntry")]
public List<XmlEntry> XmlEntries{ get; set; }
public XmlEntries()
{
XmlEntries = new List<XmlEntry>();
}
public XmlEntries(IEnumerable<XmlEntry> entries)
{
XmlEntries= entries.ToList();
}
}
的XmlEntry类是这样的:
public class XmlEntry
{
[XmlArrayItem("XmlSubEntry")]
public List<XmlSubEntry> XmlSubEntries{ get; set; }
}
和XmlSubEntry看起来是这样的。
public class XmlSubEntry
{
string AttributeOne{ get; set; }
int? AttributeTwo{ get; set; }
}
我已经使用小提琴手发送以下XML
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<XmlEntries>
<XmlEntry>
<XmlSubEntries>
<XmlSubEntry>
<AttributeOne>P</AttributeOne>
<AttributeTwo>8</AttributeTwo>
</XmlSubEntry>
<XmlSubEntry>
<AttributeOne>S</AttributeOne>
<AttributeTwo>26</AttributeTwo>
</XmlSubEntry>
</XmlSubEntries>
</XmlEntry>
</XmlEntries>
</Root>
我的问题是XmlSubEntry的属性从来没有得到正确的序列化。当调试在apiController条目MethodCall将含有1个XmlEntry与XmlSubEntries为2 XmlSubEntry的列表的列表,但属性(AttributeOne和AttributeTwo)总是零。
我试图诠释着班,我可以的事情,但我还是不会得到属性序列化correctry所有方式。
有没有解决任何XML的忍者可以帮我找出我做错了什么?
谢谢。我让它比我需要的更复杂。这个解决方案隐藏了我的视线。 :) –