0

考虑以下 XML:

<events xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" artist="Rammstein"    festivalsonly="0" page="1" perPage="50" totalPages="1" total="25">
    <event xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
        <id>1985967</id>
        <title>Rammstein: "Made in Germany 1995 -2011 LIVE"</title>
        <artists>
            <artist>Rammstein</artist>
            <artist>Deathstars</artist>
            <headliner>Rammstein</headliner>
        </artists>
    </event>
</events>

我想将下面的所有标签反序列artists化为一个列表。到目前为止我所拥有的:

public class Artist
{
    public string Value { get; set; }
}

public class HeadLiner : Artist
{

}

public class ArtistCollection : List<Artist>
{

}

public class Event
{
    public ArtistCollection Artists { get; set; }
}

我希望最终得到一个包含 3 个项目的列表(两位艺术家和一位头条新闻),但我只得到艺术家。是否有可能使用 Restsharp 开箱即用地实现这种行为?还是我需要自定义序列化程序?

使用属性,我想我需要这个XmlInclude属性,但到目前为止我很喜欢 Restsharp 的“开箱即用”部分。

4

1 回答 1

0

从你的帖子之日起,我可能有点晚了,但迟到总比没有好。

我相信你的 xml 需要更像这样:

<events xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" artist="Rammstein"    festivalsonly="0" page="1" perPage="50" totalPages="1" total="25">
   <event xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
       <id>1985967</id>
       <title>Rammstein: "Made in Germany 1995 -2011 LIVE"</title>
       <artists>
           <artist>Rammstein</artist>
           <artist>Deathstars</artist>
           <artist xsi:type="headliner">Rammstein</artist>
       </artists>
   </event>
</events>
于 2012-04-27T16:24:08.887 回答