Exemplo n.º 1
0
        Allquestions getquestion()
        {
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            StringBuilder sb = new StringBuilder();

            byte[]          buf        = new byte[8192];
            HttpWebRequest  request    = (HttpWebRequest)WebRequest.Create("https://opentdb.com/api.php?amount=10");
            HttpWebResponse responce   = (HttpWebResponse)request.GetResponse();
            Stream          resstream  = responce.GetResponseStream();
            string          tempString = null;

            int count = 0;

            do
            {
                count = resstream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                }
            }while (count > 0);
            JavaScriptSerializer ser = new JavaScriptSerializer();

            Allquestions response = ser.Deserialize <Allquestions>(tempString);

            return(response);
        }
Exemplo n.º 2
0
        private void makeQestion()
        {
            int questionNumber = (int)Session["questionNumber"];

            ((Allquestions)Session["question"]).results[questionNumber].incorrect_answers.Add(((Allquestions)Session["question"]).results[questionNumber].correct_answer);
            RadioButtonList1.Items.Clear();
            Allquestions quest = (Allquestions)Session["question"];

            category.Value  = HttpUtility.HtmlDecode(quest.results[questionNumber].category);
            questions.Value = HttpUtility.HtmlDecode(quest.results[questionNumber].question);

            quest.results[questionNumber].incorrect_answers = Shuffle <String>(quest.results[questionNumber].incorrect_answers);
            int i = 1;

            foreach (string s in quest.results[questionNumber].incorrect_answers)
            {
                RadioButtonList1.Items.Add(new ListItem(s, i.ToString()));
                RadioButtonList1.Items[i - 1].Text += "<span class=\"checkmark\"></span>";
                i++;
            }
            Session["questionlist"] = RadioButtonList1;
        }