public Question(QuestionType.QType qType, String qText, String cAnswer, int index) { this.index = index; this.CorrectAnswer = cAnswer; this.QType = qType; this.QuestionText = qText; }
public void loadQuestions() { // read JSON directly from a file using (StreamReader file = File.OpenText(@"questions.json")) using (JsonTextReader reader = new JsonTextReader(file)) { data = (JArray)JToken.ReadFrom(reader); } this.label1.Text = "There are " + data.Count + " questions available"; int counter = 0; questions = new List <Question>(); foreach (var item in data.Children()) { var itemProperties = item.Children <JProperty>(); //int index = (int)itemProperties.FirstOrDefault(x => x.Name == "_id").Value; string qt = itemProperties.FirstOrDefault(x => x.Name == "QType").Value.ToString(); QuestionType.QType qType = (QuestionType.QType)Enum.Parse(typeof(QuestionType.QType), qt, true); string CorrectAnswer = itemProperties.FirstOrDefault(x => x.Name == "CorrectAnswer").Value.ToString(); string QuestionText = itemProperties.FirstOrDefault(x => x.Name == "QuestionText").Value.ToString(); questions.Add(new Question(qType, QuestionText, CorrectAnswer, counter++)); } qQuantily = data.Count; }