Ejemplo n.º 1
0
        private void ReadquestionsFromString(TrivialPersuit game, string jsonstring)
        {
            game.questions.Clear();
            dynamic jsonData = JsonConvert.DeserializeObject(jsonstring);
            JArray  data     = jsonData.data;

            for (int i = 0; i < data.Count; i++)
            {
                dynamic dataInArray = data[i];
                string  question    = dataInArray.question;
                string  ranswer     = dataInArray.ranswer;
                string  answer2     = dataInArray.answer2;
                string  answer3     = dataInArray.answer3;
                string  answer4     = dataInArray.answer4;

                game.questions.Add(new QuestionAnswer(question, ranswer, answer2, answer3, answer4));
            }
        }
Ejemplo n.º 2
0
        public void ReadquestionfromFile(TrivialPersuit game)
        {
            string       lines  = "";
            StreamReader reader = new StreamReader(@"D:\jsonFile.json");

            try
            {
                do
                {
                    lines += reader.ReadLine();
                }while (reader.Peek() != -1);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            finally
            {
                reader.Close();
                ReadquestionsFromString(game, lines);
            }
        }