public void toJson()
    {
        string path       = "Assets/Data/path.json";
        string jsonString = File.ReadAllText(path);
        Dictionary <String, object> result = JsonConvert.DeserializeObject <Dictionary <String, object> >(jsonString);
        int count = result.Keys.Count;

        Debug.Log("count => " + count);
        MyJsonDictionary <String, object> Question = new MyJsonDictionary <String, object>();

        result["Question" + (count + 1)] = Question;
        int index = 0;

        foreach (object VARIABLE in key)
        {
            Question[VARIABLE.ToString()] = value[index];
            index++;
        }

        Question["solved"] = false;
        Debug.Log(Serialize(result));
        string data = Serialize(result);

        System.IO.File.WriteAllText("Assets/Data/path.json", data);
        for (int i = 0; i < _list.Count; i++)
        {
            _list.RemoveAt(i);
        }
        value = new object[2];
        key   = new object[2];
    }
Esempio n. 2
0
    public void WriteQuestion()
    {
        MyJsonDictionary <String, object> result = new MyJsonDictionary <String, object>();
        //result["foo"] = "bar";
        //result["Name"] = "John Doe";
        //result["Age"] = 32;
        MyJsonDictionary <String, object> Question = new MyJsonDictionary <String, object>();

        result["Question"] = Question;
        Question["okula"]  = 2;
        Question["ben"]    = 1;
        Question["gittim"] = 3;
        Question["solved"] = false;
        MyJsonDictionary <String, object> Question1 = new MyJsonDictionary <String, object>();

        result["Question1"]     = Question1;
        Question1["gideceğimi"] = 4;
        Question1["zaman"]      = 2;
        Question1["bilmiyorum"] = 5;
        Question1["ne"]         = 1;
        Question1["eve"]        = 3;
        Question1["solved"]     = false;

        Debug.Log(Serialize(result));
        string data = Serialize(result);

        System.IO.File.WriteAllText("Assets/Data/path.json", data);
    }
    public void toJson1()
    {
        string path       = "Assets/Data/path.json";
        string jsonString = File.ReadAllText(path);
        MyJsonDictionary <String, object> exactResult = new MyJsonDictionary <String, object>();

        Dictionary <String, object> result1 = JsonConvert.DeserializeObject <Dictionary <String, object> >(jsonString);
        // Debug.Log(  "result 1 => " + Serialize( result1["Question"] )  );
        int count = 0;

        foreach (object VARIABLE in result1.Keys)
        {
            object readquestionStr = result1[VARIABLE.ToString()];
            Dictionary <String, object>       result2        = JsonConvert.DeserializeObject <Dictionary <String, object> >(readquestionStr.ToString());
            MyJsonDictionary <String, object> forOneQuestion = new MyJsonDictionary <String, object>();
            exactResult["Question" + count] = forOneQuestion;
            foreach (object VARIABLE2 in result2.Keys)
            {
                if (VARIABLE2.ToString().Equals("__type") || VARIABLE2.ToString().Equals("solved"))
                {
                    continue;
                }
                object readquestion2Str = VARIABLE2.ToString();
                Debug.Log("keys => " + readquestion2Str.ToString());
                forOneQuestion[readquestion2Str.ToString()] = result2[VARIABLE2.ToString()];
            }

            count++;
        }



        MyJsonDictionary <String, object> newQuestion = new MyJsonDictionary <String, object>();

        exactResult["Question" + (count)] = newQuestion;
        int index = 0;

        foreach (object VARIABLE in key)
        {
            newQuestion[VARIABLE.ToString()] = value[index];
            index++;
        }

        newQuestion["solved"] = false;



        //object readquestion2Str = result1["Question"];
        //Dictionary<String, object> ReadQuestion2 = JsonConvert.DeserializeObject<Dictionary<String, object>>( readquestion2Str.ToString());

        //MyJsonDictionary<String, object> result = new MyJsonDictionary<String, object>();



        //result["foo"] = "bar";
        //result["Name"] = "John Doe";
        //result["Age"] = 32;


        Debug.Log("exact => " + Serialize(exactResult));
        string data = Serialize(exactResult);

        System.IO.File.WriteAllText("Assets/Data/path.json", data);
    }