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"]); }
public void WriteList() { var outputStream = new MemoryStream(); var writer = new JsonParseNodeWriter(outputStream); writer.WriteStartDocument(); writer.WriteStartList(); writer.WriteListItem("hello", (w, s) => w.WriteValue(s)); writer.WriteListItem("world", (w, s) => w.WriteValue(s)); writer.WriteEndList(); writer.WriteEndDocument(); writer.Flush(); outputStream.Position = 0; var json = new StreamReader(outputStream).ReadToEnd(); var jarray = JArray.Parse(json); Assert.Equal(2, jarray.Count); }
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"]); }