데이터를 수집하고 Json에서 구조를 반환하는 데 사용하는 다음 클래스가 있습니다. 당신이 볼 수 있듯이Newtonsoft Json이 클래스를 직렬화하지 않습니다
public class Outcome {
public int id { get; set; }
public string outcome { get; set; }
public string actionStep { get; set; }
public List<OutcomeActionResult> actionResults { get; set; }
public void setData(SqlDataReader reader, DateData dateData) {
this.id = Convert.ToInt32(reader["id"]);
this.outcome = Convert.ToString(reader["outcome"]);
this.actionStep = Convert.ToString(reader["action_step"]);
this.actionResults = new Outcomes().getActionResultByOutcomeId(this.id, dateData);
}
}
public class OutcomeActionResult {
public int id { get; set; }
public string actionResult { get; set; }
public ActionResultQuestion question { get; set; }
public void setData(SqlDataReader reader, DateData dateData) {
this.id = Convert.ToInt32(reader["id"]);
this.actionResult = Convert.ToString(reader["action_result"]);
this.question = new Outcomes().getActionResultQuestionByActionResultId(this.id, dateData);
}
}
public class ActionResultQuestion {
public int id { get; set; }
public string question { get; set; }
public bool isMultipleChoice { get; set; }
public List<MultipleChoiceOption> multipleChoiceOptions { get; set; }
ActionResultAnswer answer { get; set; }
public void setData(SqlDataReader reader, DateData dateData) {
this.id = Convert.ToInt32(reader["id"]);
this.question = Convert.ToString(reader["question"]);
this.isMultipleChoice = Convert.ToBoolean(reader["is_multi"]);
this.answer = new Outcomes().getActionResultAnswersByIdAndDate(this.id, dateData.year, dateData.month, dateData.day, dateData.shiftId);
}
}
public class ActionResultAnswer {
public int id { get; set; }
public string notes { get; set; }
public int employeeId { get; set; }
public int selectedAnswer { get; set; }
public string answer { get; set; }
public int year { get; set; }
public int month { get; set; }
public int day { get; set; }
public int shiftId { get; set; }
public void setData(SqlDataReader reader) {
this.id = Convert.ToInt32(reader["id"]);
this.notes = Convert.ToString(reader["notes"]);
this.employeeId = Convert.ToInt32(reader["employee_id"]);
this.selectedAnswer = reader.IsDBNull(reader.GetOrdinal("selected_answer")) ? -1 : Convert.ToInt32(reader["selected_answer"]);
this.answer = Convert.ToString(reader["answer"]);
this.year = Convert.ToInt32(reader["year"]);
this.month = Convert.ToInt32(reader["month"]);
this.shiftId = Convert.ToInt32(reader["shift_id"]);
}
}
, 나는 ActionResultAnswer이있는 ActionResultQuestion을 포함하고, 각각의 OutcomeActionResults의 목록이 포함되어 결과가 있습니다. 이런 식으로 뭔가 :
결과 -> 목록 (OutcomeActionResult) -> ActionResultQuestion -> ActionResultAnswer
내가 코드를 단계별로 할 때, 모든 데이터가 제대로 설치되고 모든 것이 괜찮습니다. 그러나 JSON 개체 구조를 serialize 할 때 ActionResultAnswer 제외한 모든 serialize합니다. 기본적으로 구조의 가장 깊은 레벨은 잘게 잘립니다. 왜 이런 일이 일어나고 있는지, 어떻게 일어나지 않는지 알 수있는 것을 찾지 못했습니다.
은 아마 여기까지 개체를 직렬화 코드를 넣어한다고 : 당신의ActionResultQuestion
클래스
var response = outcomes.getOutcomesByClientAndDate(clientId, year, month, day, shiftId, dayOfWeek);
var json = JsonConvert.SerializeObject(response);
신성한 쓰레기. 나는 그것을 어떻게 놓쳤는가? 감사. –