如何使用 RestSharp 进行 XmlDeserialize? [英] How to XmlDeserialize using RestSharp?

查看:47
本文介绍了如何使用 RestSharp 进行 XmlDeserialize?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 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>

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

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?

推荐答案

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

You need to create the class by hand, befoe you can deserialize the XML:

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

您应该能够使用以下内容进行反序列化:

The you should be able to deserialize using something like:

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

(看这里:测试 RestSharp 的反序列化没有适当的 REST-Api)

这篇关于如何使用 RestSharp 进行 XmlDeserialize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆