XML 数组反序列化 C#
本文关键字:反序列化 数组 XML | 更新日期: 2023-09-27 17:56:16
我一直在试图弄清楚出了什么问题,但一直无法弄清楚。也许您可以看到我在反序列化此提要时出错的地方。
从XML提要中,我有这个结构:
<Recommendation>
<screenshot-urls>
<screenshots d="320x480">
<screenshot orientation="portrait" w="320" h="480">url1</screenshot>
<screenshot orientation="portrait" w="320" h="480">url2</screenshot>
<screenshot orientation="portrait" w="320" h="480">url3</screenshot>
<screenshot orientation="portrait" w="320" h="480">url4</screenshot>
</screenshots>
<screenshots d="480x800">
<screenshot orientation="portrait" w="480" h="800">url1</screenshot>
<screenshot orientation="portrait" w="480" h="800">url2</screenshot>
<screenshot orientation="portrait" w="480" h="800">url3</screenshot>
<screenshot orientation="portrait" w="480" h="800">url4</screenshot>
</screenshots>
</screenshot-urls>
</recommendation>
我已经排列了以下代码,我已经尝试了各种事情,但我得到的最接近的是有一个 4 个屏幕截图的数组,这些屏幕截图仅使用第一个屏幕截图的 URL。
public class Recommendation
{
/// <remarks />
[XmlElement("screenshot-urls")]
public TopAppScreenshots[] screenshoturls { get; set; }
public class TopAppScreenshots
{
public TopAppScreenshot[] Screenshots { get; set; }
public class TopAppScreenshot
{
[XmlAttribute("w")]
public string Width { get; set; }
[XmlAttribute("h")]
public string Height { get; set; }
[XmlAttribute("orientation")]
public string Orientation { get; set; }
[XmlText]
public string ScreenshotUrl { get; set; }
}
}
}
目前使用此代码,屏幕截图对象为空,但查看其他示例,我真的认为此代码应该有效。我做错了什么?
public class Recommendation
{
[XmlArray("screenshot-urls")]
[XmlArrayItem("screenshots")]
public TopAppScreenshots[] Screenshoturls { get; set; }
public class TopAppScreenshots
{
[XmlElement("screenshot")]
public TopAppScreenshot[] Screenshot { get; set; }
[XmlAttribute("d")]
public string Dimension { get; set; }
public class TopAppScreenshot
{
[XmlAttribute("w")]
public string Width { get; set; }
[XmlAttribute("h")]
public string Height { get; set; }
[XmlAttribute("orientation")]
public string Orientation { get; set; }
[XmlText]
public string ScreenshotUrl { get; set; }
}
}
}