Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将元素名称反序列化为RestSharp中的属性_C#_Restsharp - Fatal编程技术网

C# 将元素名称反序列化为RestSharp中的属性

C# 将元素名称反序列化为RestSharp中的属性,c#,restsharp,C#,Restsharp,不幸的是,我查询的API返回的XML如下: <coupon> <discount_in_cents> <USD type="integer">500</USD> <EUR type="integer">450</EUR> </discount_in_cents> </coupon> 我有一个我正在尝试填充的列表 public List<Discount>

不幸的是,我查询的API返回的XML如下:

<coupon>   
  <discount_in_cents>
    <USD type="integer">500</USD>
    <EUR type="integer">450</EUR> 
  </discount_in_cents>
</coupon>
我有一个我正在尝试填充的列表

public List<Discount> {get;set;}

public class Discount
{
    public string CurrencyType {get;set;}
    public int Value {get;set;}
}

Value属性设置正确,但我需要在CurrencyType属性(如CurrencyType=USD)中填充元素名称。如何让RestSharp用元素名填充CurrencyType?

您可以尝试使用[XmlRoot]和[XmlElement]属性来设置类和xml之间的依赖关系