Exemple #1
0
        public void TestCreate()
        {
            // create a document and root
            var doc = JSONDocument.CreateDocument();

            doc.Root = doc.CreateItemObject();

            // add some items to root: use explicit creation of items
            doc.RootAsObject.Add("FirstName", doc.CreateItemString("Hans"));
            doc.RootAsObject.Add("LastName", doc.CreateItemString("Wurst"));
            doc.RootAsObject.Add("age", doc.CreateItemNumber(42));

            // create and add an object and fill, use implicit creation of items
            var address = doc.CreateItemObject();

            address.Add("street", "infinite loop 0");
            address.Add("city", "Duckburg");
            doc.RootAsObject.Add("Address", address);

            // create and add an array
            var childAge = doc.CreateItemArray();

            childAge.Add(3);
            childAge.Add(10);
            childAge.Add(12);
            doc.RootAsObject.Add("AgeOfChildren", childAge);

            Assert.NotNull(doc.Root);
            Assert.NotNull(doc.RootAsObject["FirstName"] as IJSONItemString);

            Assert.True(((IJSONItemString)doc.RootAsObject["FirstName"]).Value != null);
        }
Exemple #2
0
        public void TestWrite()
        {
            var doc = JSONDocument.CreateDocument();

            doc.Root = doc.CreateItemNumber(42);
            var json = JSONWriter.CreateUnformattedWriter().WriteToString(doc);

            Assert.True(json.IndexOf("42") >= 0);
        }
Exemple #3
0
        /// <summary>
        /// Converts data into JSON for computer graphics
        /// </summary>
        public void ToJSON()
        {
            IJSONDocument  doc = JSONDocument.CreateDocument();
            IJSONItemArray arr = doc.CreateItemArray();

            foreach (Beam b in this.GetAllProperties())
            {
                IJSONItem o = b.ToJSON(doc);
                arr.Add(o);
            }
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            // create a document and root
            var doc = JSONDocument.CreateDocument();

            doc.Root = doc.CreateItemObject();

            // add some items to root: use explicit creation of items
            doc.RootAsObject.Add("FirstName", doc.CreateItemString("Hans"));
            doc.RootAsObject.Add("LastName", doc.CreateItemString("Wurst"));
            doc.RootAsObject.Add("age", doc.CreateItemNumber(42));

            // create and add an object and fill, use implicit creation of items
            var address = doc.CreateItemObject();

            address.Add("street", "infinite loop 0");
            address.Add("city", "Duckburg");
            doc.RootAsObject.Add("Address", address);

            // create and add an array
            var childAge = doc.CreateItemArray();

            childAge.Add(3);
            childAge.Add(10);
            childAge.Add(12);
            doc.RootAsObject.Add("AgeOfChildren", childAge);

            // write to a JSON string
            var jsonString = JSONWriter.CreateUnformattedWriter().WriteToString(doc);

            // output
            Console.WriteLine(jsonString);


            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }