Restsharp - 反序列化xml以列出元素标记包含唯一ID的位置

时间:2014-01-15 18:41:38

标签: c# rest deserialization restsharp

我正在使用基于Rest的服务(称为Solve360的CRM系统),例如我在这里抓取一个联系人列表是我从服务器收到的代码片段:

<response>
 <id99623996>
  <id>99623996</id>
  <name>Aaron</name>
  <typeid>1</typeid>
  <parentid>98830114</parentid>
  <parentcn>CC</parentcn>
  <flagged/>
  <created>2014-01-03T17:10:47+00:00</created>
  <viewed>2014-01-14T20:35:26+00:00</viewed>
  <updated>2014-01-03T17:11:13+00:00</updated>
 </id99623996>
 <id99624297>
  <id>99624297</id>
  <name>Abigail </name>
  <typeid>1</typeid>
  <parentid>98830114</parentid>
  <parentcn>CC</parentcn>
  <flagged/>
  <created>2014-01-03T17:11:01+00:00</created>
  <viewed>2014-01-03T17:11:01+00:00</viewed>
  <updated>2014-01-03T17:11:13+00:00</updated>
 </id99624297>
</response>

所以这是我的c#代码使用最新的Restsharp:

public T ExecuteSerializedCommand<T>(string resourceLoc, string method, Dictionary<string, string> parameters) where T : new() {
var request = BuildRestRequest(resourceLoc, method, parameters);
request.RootElement = "Response";
var response = RestSharpObj.Execute<T>(request);
if (response.ErrorException != null) {
    const string message = "Error retrieving response.  Check inner details for more info.";
    var rsMessage = new ApplicationException(message, response.ErrorException);
    throw rsMessage;
}
    return response.Data;
}

这是调用代码:

public List<Contact> GeContacts() {
    return ExecuteSerializedCommand<List<Contact>>(ITEM_CONTACTS, RESTVERB_GET, new  Dictionary<string, string>());
}

哦,我的班级联系方式:

public class Contact {
    public int id { get; set; }
    public string name { get; set; }
    public int typeid { get; set; }
    public int parentid { get; set; }
    public string parentcn { get; set; }
    public string flagged { get; set; }
    public DateTime created { get; set; }
    public DateTime viewed { get; set; }
    public DateTime updated { get; set; }
}

所以我的最终反序列化响应为null。 任何建议表示赞赏。我认为问题出在包含id号的xml标签中。不确定如何使用Restsharp处理它。

0 个答案:

没有答案