0

I have a Xamarin.Forms App and get a response.Content in XML format. How to Deserialize the data in different types in different responses ex. string , object , list . This is my code:

          client.DefaultRequestHeaders.Clear();
                    var response = await client.GetAsync($"api/users");
                    if (response.IsSuccessStatusCode)
                    {
                        var pom = await response.Content.ReadAsStringAsync();
                        ///// xml logic here
                        return pom;
                    }
                    else
                    {

                        return null;
                    }

UPDATE

I receive : <test> TEst </test> how to convert that?

RazrMan
  • 163
  • 13
  • Does this answer your question? [How to Deserialize XML document](https://stackoverflow.com/questions/364253/how-to-deserialize-xml-document) – Alexander Pope Jul 03 '20 at 12:08
  • If response.Content is a string you first need to put into a stream : StringReader reader = new StringReader(response.Content);. The you can create a XmlReader : XmlReader xReader = XmlReader.Create(reader); Then you can use any Xml Serialization like Alexander links. – jdweng Jul 03 '20 at 12:26
  • @AlexanderPope when i get only one string like in this situation: what is XMLroot what is XML ELEMENT? – RazrMan Jul 03 '20 at 12:28
  • i get just this Test – RazrMan Jul 03 '20 at 12:28
  • Are all the properties in your classes public? Does xml have namespaces? Do you have any array? Serialization is uppercase/lowercase so does the class/property names exactly match the tag names in the xml? – jdweng Jul 03 '20 at 14:28

0 Answers0