0
I need to map this XML to a C# class to deserialize via Restsharp Deserialization:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rsp stat="ok">
<items total="1232177" items="100">
<media id="4779808" thumb="http://mh-2-rest.panthermedia.net/media/previews/0004000000/04779000/04779808_thumb_170.jpg"/>
<media id="8950240" thumb="http://mh-2-rest.panthermedia.net/media/previews/0008000000/08950000/08950240_thumb_170.jpg"/>
<media id="12842738" thumb="http://mh-1-rest.panthermedia.net/media/previews/0012000000/12842000/12842738_thumb_170.jpg"/>
</items>
</rsp>
The class I Mapeed was like this:
namespace PantherMediaAPI
{
public class Media
{
public string Id { get; set; }
public string Thumb { get; set; }
}
public class Items
{
public List<Media> Media { get; set; }
public string Total { get; set; }
public string _items { get; set; }
public Items()
{
this.Media = new List<PantherMediaAPI.Media>();
}
}
public class Rsp
{
public Items Items { get; set; }
public string Stat { get; set; }
}
}
But when I get the answer all attributes come populated except the item public List<Media> Media { get; set; }
:
What am I missing? I have a lot of difficulty with XML because I work more with JSON.
Have you tried using the
Visual Studio
"XML Paste as Classes"?– Ricardo Pontual
Anyway,
public string _items
shouldn’t bepublic string items
?– Ricardo Pontual
@Ricardopunctual the deserializer understands that
_items == items
so much so that I used this site:https://xmltocsharp.azurewebsites.net/ and it returned me the same class– Leonardo Bonetti
@Ricardopunctual I will test with XML the Classes ;)
– Leonardo Bonetti
#partilGabiarra ... Xmldeserializer xml = new Xmldeserializer(); Rsp output = xml.Deserialize<Rsp>(new Restresponse { Content = text,Contenttype = "application/xml" }); var output2 = xml.Deserialize<List<Media>>(new Restresponse { Content = text,Contenttype = "application/xml" }); output.Items.Media = output2;
– Marco Souza