Exemple #1
0
        public void FileIO()
        {
            JSONNode original = new JSONNode();

            string[] values = { "a", "b", "c", "d", "e" };
            original["root"]["D"][0].asText = values[0];
            original["root"]["D"][1].asText = values[1];
            original["root"]["D"][2].asText = values[2];
            original["root"]["D"][3].asText = values[3];
            original["root"]["D"][4].asText = values[4];

            const string FILENAME = "tempFile.json";

            File.Delete(FILENAME);
            //write to file
            JSONNodeWriter w      = new JSONNodeWriter();
            var            fWrite = File.Open(FILENAME, FileMode.Create);

            w.WriteToStream(original, fWrite);
            fWrite.Close();


            //read from file
            Generator g      = new Generator();
            var       fRead  = File.Open(FILENAME, FileMode.Open);
            JSONNode  output = g.Generate(fRead);

            fRead.Close();

            var enumrtr = values.GetEnumerator();

            for (int i = 0; i < 5; i++)
            {
                enumrtr.MoveNext();
                Assert.AreEqual(enumrtr.Current, output["root"]["D"][i].asText);
            }
        }
Exemple #2
0
        public void FileIO()
        {
            JSONNode original = new JSONNode();
            string[] values = { "a", "b", "c", "d", "e" };
            original["root"]["D"][0].asText = values[0];
            original["root"]["D"][1].asText = values[1];
            original["root"]["D"][2].asText = values[2];
            original["root"]["D"][3].asText = values[3];
            original["root"]["D"][4].asText = values[4];

            const string FILENAME = "tempFile.json";
            File.Delete(FILENAME);
            //write to file
            JSONNodeWriter w = new JSONNodeWriter();
            var fWrite = File.Open(FILENAME, FileMode.Create);
            w.WriteToStream(original, fWrite);
            fWrite.Close();

            //read from file
            Generator g = new Generator();
            var fRead = File.Open(FILENAME, FileMode.Open);
            JSONNode output = g.Generate(fRead);
            fRead.Close();

            var enumrtr = values.GetEnumerator();
            for (int i = 0; i < 5; i++)
            {
                enumrtr.MoveNext();
                Assert.AreEqual(enumrtr.Current, output["root"]["D"][i].asText);
            }
        }