我在与RestSharp反序列化回报内容到我班的一个问题。 从我所有的搜索,似乎我正确的事情了。 我宁愿用RestSharp的解串器比有回落到另一个包像Newstonsoft的Json.NET。
什么我做的是作出API请求GoToWebinar为计划网络研讨会的所有名单:
var client = new RestClient(string.Format("https://api.citrixonline.com/G2W/rest/organizers/{0}/upcomingWebinars", "300000000000239000"));
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "OAuth oauth_token=" + System.Configuration.ConfigurationManager.AppSettings["GoToWebinar"]);
var response2 = client.Execute<List<RootObject>>(request);
正如你看到的,我想获得对象RootObject“列表(如下图所示)。 我收到的response2.Content以下JSON响应:
[
{
"webinarKey":678470607,
"subject":"Easton's Wild Rice Cooking Demo",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"organizerKey":300000000000239551,
"times":[{"startTime":"2012-05-09T15:00:00Z","endTime":"2012-05-09T16:00:00Z"}],
"timeZone":"America/Denver"
},
{
"webinarKey":690772063,
"subject":"Easton's Match Making Service",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"organizerKey":300000000000239551,
"times":[{"startTime":"2012-05-09T15:00:00Z","endTime":"2012-05-09T16:00:00Z"}],
"timeZone":"America/Denver"
}
]
我创建使用以下对象http://json2csharp.com使用上面的JSON结果:
public class RootObject
{
public int webinarKey { get; set; }
public string subject { get; set; }
public string description { get; set; }
public long organizerKey { get; set; }
public List<Time> times { get; set; }
public string timeZone { get; set; }
}
public class Time
{
public string startTime { get; set; }
public string endTime { get; set; }
}
问题是response2.Data总是空。 出于某种原因,反序列化失败,我不知道为什么。 我的目标是能够使用foreach循环遍历结果迭代:
foreach(RootObject r in response2.Data)
{
lblGoToWebinar.Text += r.webinarKey.ToString() + ", ";
}
为什么反序列化失败的任何想法?