예제 #1
0
        public void WriteNestedEmptyMap()
        {
            var outputStream = new MemoryStream();
            var writer       = new JsonParseNodeWriter(outputStream);

            writer.WriteStartDocument();
            writer.WriteStartMap();
            writer.WritePropertyName("intro");
            writer.WriteStartMap();
            writer.WriteEndMap();

            writer.WritePropertyName("outro");
            writer.WriteStartMap();
            writer.WriteStringProperty("good", "bye");
            writer.WriteEndMap();

            writer.WriteEndMap();
            writer.WriteEndDocument();
            writer.Flush();

            outputStream.Position = 0;
            var json    = new StreamReader(outputStream).ReadToEnd();
            var jObject = JObject.Parse(json);

            Assert.Equal("bye", jObject["outro"]["good"]);
        }
예제 #2
0
        public void WriteMap()
        {
            var outputStream = new MemoryStream();
            var writer       = new JsonParseNodeWriter(outputStream);

            writer.WriteStartDocument();
            writer.WriteStartMap();
            writer.WriteStringProperty("hello", "world");
            writer.WriteStringProperty("good", "bye");
            writer.WriteEndMap();
            writer.WriteEndDocument();
            writer.Flush();

            outputStream.Position = 0;
            var json    = new StreamReader(outputStream).ReadToEnd();
            var jObject = JObject.Parse(json);

            Assert.Equal("world", jObject["hello"]);
        }