如何反序列化具有属性的元素 [英] How to deserialize element with attribute
本文介绍了如何反序列化具有属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 RESTSharp 使用 RESTful Web 服务.XML 元素之一如下所示:
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>
而C#类POCO如下:
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; }
}
当我使用 RESTSharp 时,TempC
对象填充了单位但没有实际值;例如7.9.该值为 NULL.
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.
推荐答案
通过将属性值更改为 Value 解决了该问题.
Fixed the problem by changing the property value to Value.
更详细的例子在这里:https://github.com/restsharp/RestSharp/wiki/Deserialization
More detail example is here: https://github.com/restsharp/RestSharp/wiki/Deserialization
这篇关于如何反序列化具有属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文