使用ID作為名稱,從json對象創(chuàng)建強(qiáng)類型的c#對象我試圖利用API為一個著名的在線會議提供商。其中一個API調(diào)用返回的對象如下所示。{
"5234592":{
"pollsAndSurveys":{
"questionsAsked":1,
"surveyCount":0,
"percentageSurveysCompleted":0,
"percentagePollsCompleted":100,
"pollCount":2},
"attendance":{
"averageAttendanceTimeSeconds":253,
"averageInterestRating":0,
"averageAttentiveness":0,
"registrantCount":1,
"percentageAttendance":100}
},
"5235291":{
"pollsAndSurveys":{
"questionsAsked":2,
"surveyCount":0,
"percentageSurveysCompleted":0,
"percentagePollsCompleted":0,
"pollCount":0},
"attendance":{
"averageAttendanceTimeSeconds":83,
"averageInterestRating":0,
"averageAttentiveness":0,
"registrantCount":1,
"percentageAttendance":100}
}}我試圖在C#中創(chuàng)建一個強(qiáng)類型的對象,以便處理這些數(shù)據(jù)。我可以為pollsAndSurvey位和考勤位創(chuàng)建對象,但是我不知道如何處理id號,在本例中是5234592&5235291,這是會話的標(biāo)識符。public class AttendanceStatistics{
[JsonProperty(PropertyName = "registrantCount")]
public int RegistrantCount { get; set; }
[JsonProperty(PropertyName = "percentageAttendance")]
public float PercentageAttendance{ get; set; }
[JsonProperty(PropertyName = "averageInterestRating")]
public float AverageInterestRating { get; set; }
[JsonProperty(PropertyName = "averageAttentiveness")]
public float AverageAttentiveness { get; set; }
[JsonProperty(PropertyName = "averageAttendanceTimeSeconds")]
public float AverageAttendanceTimeSeconds { get; set; }}public class PollsAndSurveysStatistics{
[JsonProperty(PropertyName = "pollCount")]
public int PollCount { get; set; }
[JsonProperty(PropertyName = "surveyCount")]
public float SurveyCount { get; set; }
[JsonProperty(PropertyName = "questionsAsked")]
public int QuestionsAsked { get; set; }我很確定WebinarPerformanceStats是問題所在,但我不知道從哪里出發(fā)。我要改變什么才能得到NewtonSoft.Json.JsonConvert.DeserializeObject<WebinarPerformanceStats>(theJsonResponse)去工作?
- 1 回答
- 0 關(guān)注
- 334 瀏覽
添加回答
舉報
0/150
提交
取消