我正在使用 webclient 反序列化来自 web 服务的 XML 内容:
var serializer = new XmlSerializer(typeof(SearchArticles), new XmlRootAttribute("search_articles"));
var results = (SearchArticles)serializer.Deserialize(response.Content.ReadAsStreamAsync().Result);
xml内容如下:
<?xml version=\"1.0\" encoding=\"UTF-8\"?><search_articles><articles hits=\"10134\"><article><id>1763794</id>...
我的模型看起来像:
public class SearchArticles
{
[XmlElement("articles")]
public ArticleHelper articles { get; set; }
}
public class ArticleHelper
{
[XmlAttribute("hits")]
public long hits { get; set; }
[XmlElement("article")]
public List<Article> articles { get; set; }
}
public class Article
{
public long id { get; set; }
public string partner { get; set; }
public string number { get; set; }
public long number_is_generated { get; set; }
public string status { get; set; }
public long company_id { get; set; }
}
这是有效的,但我怎样才能避免拥有 ArticleHelper ?