コード例 #1
0
 static JsonObjectBuilder PutJobs(JsonObjectBuilder mainBuilder)
 {
     return(mainBuilder.PutArray("jobs", jobs =>
     {
         jobs.Push("chef");
         jobs.Push("programmer");
         jobs.Push("designer");
     }));
 }
コード例 #2
0
ファイル: JValue.cs プロジェクト: halak/jvalue
        private static JValue From(IEnumerable <KeyValuePair <string, JValue> > obj)
        {
            var builder = new JsonObjectBuilder(512);

            foreach (var member in obj)
            {
                builder.Put(member.Key, member.Value);
            }
            return(builder.Build());
        }
コード例 #3
0
ファイル: JsonArrayBuilder.cs プロジェクト: halak/jvalue
        public JsonArrayBuilder PushObject <T>(T value, Action <JsonObjectBuilder, T> push)
        {
            EnsureState();
            writer.WriteCommaIf(startOffset);
            var objectBuilder = new JsonObjectBuilder(writer);

            push(objectBuilder, value);
            objectBuilder.Dispose();
            return(this);
        }
コード例 #4
0
        public JsonObjectBuilder PutObject <T>(string key, T value, Action <JsonObjectBuilder, T> put)
        {
            EnsureState();
            writer.WriteCommaIf(startOffset);
            writer.WriteKey(key);
            var objectBuilder = new JsonObjectBuilder(writer);

            put(objectBuilder, value);
            objectBuilder.Dispose();
            return(this);
        }
コード例 #5
0
        public void TestObjectBuilderWithoutChaining()
        {
            var builder = new JsonObjectBuilder(1024);

            PutJobs(builder);
            builder.Put("name", "Mike");
            builder.PutNull("children");
            var complexObject = builder.Build();

            Assert.AreEqual(
                @"{""jobs"":[""chef"",""programmer"",""designer""],""name"":""Mike"",""children"":null}",
                complexObject.ToString());
コード例 #6
0
        public void TestObjectBuilder()
        {
            var simpleObject = new JsonObjectBuilder(16)
                               .Put("id", 10)
                               .Put("name", "John")
                               .Put("age", 29)
                               .Put("alive", true)
                               .PutNull("friends")
                               .Build();

            Assert.AreEqual(@"{""id"":10,""name"":""John"",""age"":29,""alive"":true,""friends"":null}", simpleObject.ToString());
            Assert.AreEqual(@"{""id"": 10, ""name"": ""John"", ""age"": 29, ""alive"": true, ""friends"": null}", simpleObject.Serialize(2));

            var complexObject = new JsonObjectBuilder(64)
                                .Put("name", "Mike")
                                .PutArray("jobs", jobs => jobs.Push("chef").Push("programmer").Push("designer"))
                                .PutNull("children")
                                .Build();

            Assert.AreEqual(
                @"{""name"":""Mike"",""jobs"":[""chef"",""programmer"",""designer""],""children"":null}",
                complexObject.ToString());
        }