我无法反序列化以下XML w / restsharp
<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块编写一个客户反序列化器?
答案 0 :(得分: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);
(看看这里:Testing the Deserialization of RestSharp without proper REST-Api)