Exemplo n.º 1
0
        IJSonMutableObject IJSonMutableObject.SetArray(string name)
        {
            IJSonMutableObject array = JSonMutableObject.CreateArray();

            SetValue(name, array);
            return(array);
        }
Exemplo n.º 2
0
        IJSonMutableObject IJSonMutableObject.InsertArrayAt(int index)
        {
            IJSonMutableObject array = JSonMutableObject.CreateArray();

            InsertValue(index, array);
            return(array);
        }
Exemplo n.º 3
0
        public void CreateMutableObjectFromScratch()
        {
            var jo   = JSonMutableObject.CreateDictionary();
            var now  = DateTime.Now;
            var guid = Guid.NewGuid();

            jo.SetValue("name", "Paweł");
            jo.SetValue("age", 12);
            jo.SetValue("date", now, JSonDateTimeKind.Ticks);
            jo.SetValue("id", guid);
            jo.SetNull("school");

            var sa = jo.SetArray("items");

            sa.SetValue(1);
            sa.SetValue(2);
            sa.SetValue(3);

            var so = jo.SetDictionary("location");

            so.SetValue("latitude", 1.23d);
            so.SetValue("longigute", 1.24d);
            so.SetValue("city", "WRO");
            so.SetValue("country", "PL");

            var dates = JSonMutableObject.CreateArray();

            dates.SetValue(now.AddDays(1));
            dates.SetValue(now.AddMinutes(100));
            dates.SetValue(now.AddYears(2));

            jo.SetValue("dates", dates);

            writer.Write(jo);
            Assert.IsNotNull(writer.ToString(), "Should serialize as some kind of data!");

            var ic = jo.CreateImmutableClone(); // create immutable clone, where the values will be checked!

            Assert.IsTrue(ic.Contains("school"), "Should contain the 'school' item!");
            Assert.IsNull(ic["school"].StringValue, "'school' item should be equal to null!");
            Assert.AreEqual(now, ic["date"].ToDateTimeValue(JSonDateTimeKind.Ticks), "Incompatible current date!");
            Assert.AreEqual(3, ic["items"].Count, "There should be sub-array with 3 items!");
            Assert.AreEqual(2, ic["items"][1].Int32Value, "Invalid sub-array item value!");
            Assert.AreEqual(1.23d, ic["location"]["latitude"].DoubleValue, "Invalid latitude!");
        }
Exemplo n.º 4
0
 IJSonMutableObject IJSonObject.CreateMutableClone()
 {
     return(JSonMutableObject.CreateArray(this));
 }