编辑:结果我可以很好地反序列化,问题实际上是当我尝试循环获取问题时。尽管“对象引用未设置为对象的实例”,但出现相同的错误。我只是在编辑这个,因为我现在不能删除这个帖子,因为它有答案。
//deserialize json
ResponsesList responses = JsonConvert.DeserializeObject<ResponsesList>(_ResponseContent);
if (responses != null)
{
//loop through responses
foreach (ResponsesList.Data data in responses.data)
foreach (ResponsesList.Questions question in data.questions)
foreach (ResponsesList.Answer answer in question.answers)
{
//upsert each response
UpsertResponse(survey_id, data.respondent_id, question.question_id, answer.row, answer.col);
}
}
这一行是发生错误的地方
foreach (ResponsesList.Questions question in data.questions)
这是我要反序列化的类
//get_responses
public class ResponsesList
{
public int status { get; set; }
public List<Data> data { get; set; }
public class Data
{
public string respondent_id { get; set; }
public List<Questions> questions { get; set; }
}
public class Questions
{
public List<Answer> answers { get; set; }
public string question_id { get; set; }
}
public class Answer
{
public string row { get; set; }
public string col { get; set; }
}
}