C# XML Deserialize Array elements null

inficling

New Member
I'm trying to deserialize a reponse from a REST API.\[code\]"<FieldListDTO xmlns=\"api.playcento.com/1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Allfield><FieldDTO><Fieldname>Mobile nr</Fieldname><Fieldtype>T</Fieldtype><Fieldvalue>003241234578</Fieldvalue><Fk_id_page>CP584ea74ce5ad4e2d8561d75fc6944f96</Fk_id_page><Id_field>FI152dcde5ef9849898b12d6a3f2cdb4ee</Id_field><Required>true</Required></FieldDTO></Allfield><Totalcount>1</Totalcount></FieldListDTO>"\[/code\]The Field class:\[code\]namespace PlaycentoAPI.Model{ [XmlRoot("FieldListDTO",Namespace = "api.playcento.com/1.0")] [XmlType("FieldListDTO")] public class FieldListDTO { public FieldListDTO() { } [XmlElement("Totalcount")] public int TotalCount { get; set; } [XmlArray("Allfield")] [XmlArrayItem("FieldDTO", typeof(Field))] public Field[] Field { get; set; } } [XmlRoot("FieldDTO", Namespace = "api.paycento.com/1.0")] [XmlType("FieldDTO")] public class Field { public Field() { } [XmlElement("Id_field")] public string ID_Field { get; set; } [XmlElement("Fieldtype")] public string FieldType { get; set; } [XmlElement("Fk_id_page")] public string FK_ID_PAGE { get; set; } [XmlElement("Required")] public bool Required { get; set; } [XmlElement("Fieldname")] public string FieldName { get; set; } [XmlElement("Fieldvalue")] public string FieldValue { get; set; } }}\[/code\]My code which calls the API and deserializes it:\[code\]string response = Helper.PerformAndReadHttpRequest(uri, "GET", ""); FieldListDTO myObject; XmlReaderSettings settings = new XmlReaderSettings(); using (StringReader textReader = new StringReader(response)) { using (XmlReader xmlReader = XmlReader.Create(textReader, settings)) { XmlSerializer mySerializer = new XmlSerializer(typeof(FieldListDTO)); myObject = (FieldListDTO)mySerializer.Deserialize(xmlReader); } } return myObject.Field;\[/code\]In my actual response, I'm getting back 14 FieldDTO's. After deserializing the xml, FieldListDTO myObject contains TotalCount = 14 and Field is an array containing 14 Field's. But all the properties of these fields are NULL (or false).I'm using the same method for several other API calls. I've compared the classes and the only difference that I see is that the class (Field) has an bool property. So I thought that was the problem. I've changed the bool property to a string but still all the properties were NULL after deserialization.
 
Back
Top