コード例 #1
0
    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);
    }