我在尝试访问HTTP GET中的foreach循环内的类文件的成员时遇到问题。在过去,当我完成这项工作时,我已经能够创建foreach循环并访问类文件,以测试拉取数据。但现在当我进入d。我的班级成员都没有。我不明白我在这里做错了什么。
班级档案:
class WhoIsOnCallParse : IEnumerable
{
public int CommonId { get; set; }
public int DurationWorked { get; set; }
public bool IsOnCall { get; set; }
public int ScheduleRotationId { get; set; }
public int GroupId { get; set; }
public int GroupRoleId { get; set; }
public string CurrentMemberEndDate { get; set; }
public string CurrentMemberStartDate { get; set; }
public int RotationPosition { get; set; }
public int Duration { get; set; }
public string FullName { get; set; }
public bool IsRotation { get; set; }
public int ScheduleOccurrenceId { get; set; }
public bool IsActive { get; set; }
public string RoleName { get; set; }
public string GroupName { get; set; }
public int TeamMemberLeaderCommonId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
}
HTTP呼叫方法:
public void WhoIsOnCall()
{
DateTime dte = DateTime.Today;
string fixedStartDate = String.Format("{0:yyyy-MM-dd " + "05:00:00.000" + "}", dte);
string URL = "http://oncall/api/GenerateRotation/mergedRotation/teamMemberOnCall/";
string urlParameters = "?date=" + fixedStartDate + "Z&groupRoleId=1093&scheduleRotationId=1087";
// string urlParameters = "?date=2017-04-21T18:55:15.194Z&groupRoleId=1093&scheduleRotationId=1087";
HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true });
client.BaseAddress = new Uri(URL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call!
if (response.IsSuccessStatusCode)
{
// Parse the response body. Blocking!
var oncall = response.Content.ReadAsAsync<WhoIsOnCallParse>().Result;
foreach (var d in oncall)
{
Console.WriteLine("{0}", d.); //This is where my problem is.
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
}