0
<WebxApi> 
<Search>
  <SessionId>49B9BB6E-D2BD-427E-BB38-C3BD37B216E1</SessionId> 
   </Search>
 <Search>
  <SessionId>49B9BB6E-D2BD-427E-BB38-C3BD37B216E1</SessionId> 
   </Search>
 <Search>
  <SessionId>651CE157-1ED7-4644-A6A6-93CE1FEA522D</SessionId> 
   </Search>
</WebxApi>

我在搜索的输入请求中有这个 xml,我正在尝试使用以下代码反序列化。

 var serializer = new XmlSerializer(typeof(WebxApi));
                            var sReader = new StringReader(sw.ToString());
                           var request = serializer.Deserialize(XmlReader.Create(sReader)) as WebxApi;


[Serializable]
    public class WebxApi
    {

 private List<SearchRequest> search;
 public WebxApi()
        {
            this.Search= new List<SearchRequest>();
        }
             [System.Xml.Serialization.XmlArrayAttribute()]
        public List<SearchRequest> Search
        {
            get
            {
                return search ;
            }
            set
            {
                search = value;
            }
        }
}

 [Serializable]
    public partial class SearchRequest
    {

        public string SessionId { get; set; } 

    }

所有过程都成功完成但是当我尝试获取搜索列表时给我 count= 0

谁能告诉我哪里出错了

谢谢

4

1 回答 1

0

我能够使用以下代码修复此 xml 输入请求以进行搜索。

[Serializable]
 public class WebxApi{
 private PaymentSearchRequest[] paymentSearchField;

        [DataMember]
        [System.Xml.Serialization.XmlElementAttribute("Search", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public PaymentSearchRequest[] Search
        {
            get
            {
                return this.paymentSearchField;
            }
            set
            {
                this.paymentSearchField = value;
            }
        }
    }


    [System.SerializableAttribute()]
    public partial class PaymentSearchRequest
    {

        private string sessionIdField;

        [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string SessionId
        {
            get
            {
                return this.sessionIdField;
            }
            set
            {
                this.sessionIdField = value;
            }
        }

    }
于 2013-11-22T12:34:46.013 回答