1

这是我从网站上获得的 Xml:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="[url]">
  <totalResults>1</totalResults>
  <movie code="134539" />
  <movie code="134540" />
</feed>

我的 C# 类:

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

[Serializable]
[XmlRoot("feed", Namespace = "[url]")]
public class FeedSearch
{
    [XmlElement("totalResults")]
    public int TotalResults
    { get; set; }

    [XmlArray("feed")]
    [XmlArrayItem("movie")]
    public List<MovieSearch> Movies
    { get; set; }
}

using System;
using System.Xml.Serialization;

[Serializable]
[XmlRoot("movie", Namespace = "[url]")]
public class MovieSearch
{
    [XmlAttribute("code")]
    public int Code
    { get; set; }
}

TotalResults 总是很好地反序列化,但我的电影列表总是空的,为什么?

4

1 回答 1

5

代替:

[XmlArray("feed")]
[XmlArrayItem("movie")]
public List<MovieSearch> Movies { get; set; }

试试这样:

[XmlElement("movie")]
public List<MovieSearch> Movies { get; set; }
于 2012-05-12T10:17:10.117 回答