如何使用 RestSharp 进行 XmlDeserialize?
我在使用 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 块编写一个自定义反序列化器?
I'm having trouble deserializing the following 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>
I can't use a class named 'Xid' with a member named 'Xid' as there is a conflict in C#. I have tried manually declaring the XmlRoot on the XidClass object, but it doesn't seem to be getting picked up by RestSharp's deserializer. Is there a way to do this with RestSharp, or am I going to need to write a custome deserializer for this particular chunk of xml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要手动创建类,然后才能反序列化 XML:
您应该能够使用类似以下内容进行反序列化:(
请查看此处:在没有适当的 REST-Api 的情况下测试 RestSharp 的反序列化)
You need to create the class by hand, befoe you can deserialize the XML:
The you should be able to deserialize using something like:
(Have a look here: Testing the Deserialization of RestSharp without proper REST-Api)