1

how to convert list obj to client.PostAsJsonAsync

My xml

<ListCustomer xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Chapter[1]">
         <item xsi:type="tns:Chapter">
             <custname xsi:type="xsd:string">sakutara</custname>
             <gender xsi:type="xsd:string">nam</gender>
             <dob xsi:type="xsd:string">21/06/1991</dob>
          </item>
</ListCustomer>

My class model

    public class item
    {
          public string custname { get; set; }
          public string gender { get; set; }
          public string dob { get; set; }
    }
    public class ListCustomer
    {
        public List<item> item { get; set; }
    }

help me please ??

AirBlack
  • 135
  • 1
  • 9
  • 1
    dupe of [this dupe](https://stackoverflow.com/questions/10518372/how-to-deserialize-xml-to-object)? – Bill Jetzer Jun 28 '20 at 10:03
  • Does this answer your question? [Convert XML String to Object](https://stackoverflow.com/questions/3187444/convert-xml-string-to-object) – Vivek Nuna Jun 28 '20 at 10:08

1 Answers1

1

You are missing namespace so I modified the xml

<Soap xmlns:xsi="MyUrl" xmlns:SOAP-ENC="MyUrl">
  <ListCustomer xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Chapter[1]">
    <item xsi:type="tns:Chapter">
      <custname xsi:type="xsd:string">sakutara</custname>
      <gender xsi:type="xsd:string">nam</gender>
      <dob xsi:type="xsd:string">21/06/1991</dob>
    </item>
  </ListCustomer>
</Soap>

Then I used following code :

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

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENANE = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENANE);
            XmlSerializer serializer = new XmlSerializer(typeof(Soap));
            Soap soap = (Soap)serializer.Deserialize(reader);
                
        }
    }
    public class item
    {
        public string custname { get; set; }
        public string gender { get; set; }
        public string dob { get; set; }
    }
    public class ListCustomer
    {
        [XmlElement("item")]
        public List<item> item { get; set; }
    }
    public class Soap
    {
        public ListCustomer ListCustomer { get; set; } 
    }
}
jdweng
  • 33,250
  • 2
  • 15
  • 20