Ejemplo n.º 1
0
    public void ParseJsonFromFacade(JSONObject menuResults, JSONObject teachingPlans)
    {
        JSONObject arr = new JSONObject (JSONObject.Type.ARRAY);
        ResultModel rm;
        QuizOptionModel qom;
        List<QuizOptionModel> options = null;

        for (int i = 0; i<menuResults.Count; i++) {
            rm = new ResultModel ();

            rm.UserID = (int)int.Parse (menuResults [i].GetField ("UserID").ToString ());
            rm.UserType = menuResults [i].GetField ("UserType").ToString ().Replace('"',' ').Trim();
            if(rm.UserType == "Teacher"){
                //Only for test needs the ONLYFORTESTSCRIPT
                rm.StudentName = PlayerPrefs.GetString("UserName");
                //Maybe solution if UserName exist in PlayerPrefs when logged in
                //rm.StudentName = PlayerPrefs.GetString("UserName");
            }

            for(int x = 0 ; x<teachingPlans.Count ; x++){
                int tempStudentID = int.Parse(teachingPlans[x].GetField("StudentID").ToString());
                if(tempStudentID == rm.UserID){
                    rm.StudentName = teachingPlans[x].GetField("StudentName").ToString().Replace('"', ' ').Trim();
                    break;
                }
            }

            options = new List<QuizOptionModel> ();
            arr = menuResults [i].GetField ("Answers");
            for (int j = 0; j<arr.Count; j++) {

                qom = new QuizOptionModel ();
                qom.Id = (int)int.Parse (arr [j].GetField ("ID").ToString ());
                qom.Title = arr [j].GetField ("Title").ToString ();
                qom.Selected = Convert.ToBoolean(arr [j].GetField ("Selected").ToString());

                options.Add (qom);
            }
            rm.Options = options;

            resultModels.Add(rm);

        }
        resultModels.Reverse ();
        ResultCalculator resCal = gameObject.GetComponent<ResultCalculator> ();

        resCal.CalculateResult (resultModels);
    }
Ejemplo n.º 2
0
    public void ParseJson(JSONObject json)
    {
        JSONObject arr = new JSONObject (JSONObject.Type.ARRAY);

        QuizPartModel qpm;
        QuizOptionModel qom;
        List<QuizOptionModel> options =null;
        for (int i = 0; i<json.Count; i++) {

            qpm = new QuizPartModel();

            string [] tempTitle =  json[i].GetField("Title").ToString().Split(' ','"');
            qpm.Title = tempTitle[3];

            //Cleans the string from escape chars
            string tempCleanQuestion = Regex.Unescape(json[i].GetField("Question").ToString());
            string cleanQuestions = tempCleanQuestion.Replace('"',' ');

            qpm.Question = cleanQuestions;

            qpm.IncludeNoAnswer = (bool)json[i].GetField("IncludeNoAnswer");
            qpm.UpperLimit = (int) int.Parse( json[i].GetField("UpperLimit").ToString());
            options = new List<QuizOptionModel>();
            arr = json[i].GetField("Options");
            for(int j = 0; j<arr.Count ; j++){

                qom= new QuizOptionModel ();
                qom.Id = (int) int.Parse(arr[j].GetField("ID").ToString());
                qom.Title = arr[j].GetField("Title").ToString().Replace('"',' ');
                if(arr[j].GetField("Selected").Equals("True")){
                qom.Selected = true;
                }else{
                    qom.Selected = false;
                }

                options.Add(qom);
            }
            qpm.Options = options;

            qpms.Add(qpm);

        }

        LoadQuizOptions lq = gameObject.GetComponent<LoadQuizOptions> ();
        lq.SetQuizOptions (qpms);
    }