反序列化XML数据时获取null

时间:2019-05-09 14:44:31

标签: c# xml

尝试反序列化以下内容:

<ArrayOfServiceQualificationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ServiceQualificationResponse>
    <status_code>1</status_code>
    <property_id>123</property_id>
    <unit_no>1</unit_no>
    <house_no>11</house_no>
    <lot_no>1</lot_no>
    <street_name>Test</street_name>
    <street_type>Lane</street_type>
    <suburb>Test Suburb</suburb>
    <state_name>NSW</state_name>
    <postcode>2008</postcode>
    <estate_name>Test Estate</estate_name>
    <stage>Test Stage</stage>
    <property_class>Test Class</property_class>
  </ServiceQualificationResponse>
</ArrayOfServiceQualificationResponse>

使用以下代码:

 var ser = new XmlSerializer(typeof(ArrayOfServiceQualificationResponse));
                    using (var xmlReader = new XmlTextReader(stringReader))
                    {
                        ArrayOfServiceQualificationResponse obj;
                        obj = (ArrayOfServiceQualificationResponse)ser.Deserialize(xmlReader);
                        xmlReader.Close();
                        return obj;
                    }

生成的对象的每个字段都有空值。我不明白为什么。

ArrayOfServiceQualificationResponse和ServiceQualificationResponse是自动生成的,如下所示:

[System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfServiceQualificationResponse", Namespace= "http://tempuri.org/", ItemName="ResponseItem")]
    [System.SerializableAttribute()]
    public class ArrayOfServiceQualificationResponse : System.Collections.Generic.List<Primus.Opticomm.Gateway.ExternalProxy.OpticommB2BService.ServiceQualificationResponse> {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="ServiceQualificationResponse", Namespace= "http://tempuri.org/")]
    [System.SerializableAttribute()]
    public partial class ServiceQualificationResponse : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

0 个答案:

没有答案