4

I'm consuming a RESTful web service by using RESTSharp. One of the XML elements looks like the following:

<temp_c units="°C">7.9</temp_c>

And the C# class POCO is as follows:

public class Test
{
    public TempC temp_c { get; set; }
}

public class TempC
{
    public string units { get; set; }
    public string value { get; set; }
}

When I use RESTSharp, I get the TempC object populated with units but not with an actual value; e.g. 7.9. The value is NULL.

Bart
  • 19,692
  • 7
  • 68
  • 77
Nil Pun
  • 17,035
  • 39
  • 172
  • 294

2 Answers2

3

Fixed the problem by changing the property value to Value.

More detail example is here: https://github.com/restsharp/RestSharp/wiki/Deserialization

Nil Pun
  • 17,035
  • 39
  • 172
  • 294
0

You need to put [XmlText] annotation in that case

public class TempC
    {
        public string units { get; set; }

        [XmlText]
        public string value { get; set; }
    }

This will tell De-serializer to get that from body of tag.

Reference link : https://groups.google.com/forum/#!topic/microsoft.public.dotnet.xml/loj2CBoyCnE

Dhrumil Bhankhar
  • 1,301
  • 1
  • 14
  • 15