【问题标题】:How to XmlDeserialize using RestSharp?如何使用 RestSharp 进行 XmlDeserialize?
【发布时间】:2011-10-14 22:12:29
【问题描述】:

我在使用 restsharp 反序列化以下 XML 时遇到问题

<Xid>
   <Id>118</Id>
   <Active>true</Active>
   <Xid>20</Xid>
   <CreatedDate>2011-09-16T18:15:32</CreatedDate>
   <CreatedUserId>1782</CreatedUserId>
   <ModifiedDate>2011-09-16T18:15:32</ModifiedDate>
   <ModifiedUserId>1782</ModifiedUserId>
   <TableName>ProjectRate</TableName>
   <ObjectId>644</ObjectId>
   <SystemGuid>157f2e2d-5e8b-41c7-b932-09c1d75d0ccc</SystemGuid>
</Xid>

我不能将名为“Xid”的类与名为“Xid”的成员一起使用,因为 C# 中存在冲突。我曾尝试在 XidClass 对象上手动声明 XmlRoot,但它似乎并没有被 RestSharp 的反序列化器拾取。有没有办法用 RestSharp 做到这一点,还是我需要为这个特定的 xml 块编写一个自定义反序列化器?

【问题讨论】:

    标签: c# xml serialization restsharp


    【解决方案1】:

    您需要手动创建类,然后才能反序列化 XML:

    public class Xid
    {
        public int Id { get; set; }
        public bool Active { get; set; }
        public int Xid { get; set; }
        ...
    }
    

    你应该能够使用类似的东西来反序列化:

    Xid xid = xml.Deserialize<Xid>(response);
    

    (看看这里:Testing the Deserialization of RestSharp without proper REST-Api

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      相关资源
      最近更新 更多