2

我在使用 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 块编写一个自定义反序列化器?

4

1 回答 1

0

您需要手动创建类,然后才能反序列化 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);

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

于 2012-02-24T09:07:13.910 回答