具有RestSharp反序列化的POCO类的XML属性

时间:2018-04-01 17:00:16

标签: c# xml rest restsharp

我的回复如下:

<CONTENT>
      <SEND_SMS_SUCCESS>
         <TRANSACTION id="30911386"/>
         <VALID_SMS_COUNT>2</VALID_SMS_COUNT>
         <INVALID_SMS_COUNT>0</INVALID_SMS_COUNT>
      </SEND_SMS_SUCCESS>
</CONTENT>

和我的班级:

public class CONTENT
{
    public SEND_SMS_SUCCESS SEND_SMS_SUCCESS  { get; set; }
}

public class SEND_SMS_SUCCESS
{
    [XmlElement("TRANSACTION")]
    public TRANSACTION TRANSACTION { get; set; }
    public int VALID_SMS_COUNT { get; set; }
    public int INVALID_SMS_COUNT { get; set; }
}
public struct TRANSACTION
{
    [XmlAttribute("id")]
    public string ID { get; set; }

}

我正在使用RestSharp:

var response = client.Execute<CONTENT>(request);

但我无法获得Transaction.ID。它的值为null。我怎样才能获得这个属性?

1 个答案:

答案 0 :(得分:0)

我删除了XmlAttribute和XmlElement并添加了Deserialize属性:

    [DeserializeAs(Name = "id")]
    public string ID { get; set; }