本文整理汇总了C#中JsonWriter.WriteEnd方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteEnd方法的具体用法?C# JsonWriter.WriteEnd怎么用?C# JsonWriter.WriteEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteEnd方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritesEmptyArray
public void WritesEmptyArray()
{
var sw = new StringWriter();
var writer = new JsonWriter(sw);
writer.WriteStartArray();
writer.WriteEnd();
Assert.AreEqual("[]", sw.ToString());
}
示例2: WritesEmptyObject
public void WritesEmptyObject()
{
var sw = new StringWriter();
var writer = new JsonWriter(sw);
writer.WriteStartObject();
writer.WriteEnd();
Assert.AreEqual("{}", sw.ToString());
}
示例3: WritesSinglePropertyArray
public void WritesSinglePropertyArray()
{
var sw = new StringWriter();
var writer = new JsonWriter(sw);
writer.WriteStartArray();
writer.WriteValue(1);
writer.WriteEnd();
Assert.AreEqual("[1]", sw.ToString());
}
示例4: WritesSinglePropertyObject
public void WritesSinglePropertyObject()
{
var sw = new StringWriter();
var writer = new JsonWriter(sw);
writer.WriteStartObject();
writer.WriteName("A").WriteValue(1);
writer.WriteEnd();
Assert.AreEqual("{\"A\": 1}", sw.ToString());
}
示例5: EndOutsideObject
public void EndOutsideObject()
{
var sw = new StringWriter();
var writer = new JsonWriter(sw);
try {
writer.WriteEnd();
Assert.Fail("Did not throw the expected exception");
} catch (NotSupportedException ex) {
Assert.AreEqual("Need to be inside an Array, Object or Constructor to End", ex.Message);
}
}
示例6: HandleError
private void HandleError(JsonWriter writer, int initialDepth)
{
ClearErrorContext();
while (writer.Top > initialDepth)
{
writer.WriteEnd();
}
}
示例7: HandleError
private void HandleError(JsonWriter writer, int initialDepth)
{
ClearErrorContext();
if (writer.WriteState == WriteState.Property)
writer.WriteNull();
while (writer.Top > initialDepth)
{
writer.WriteEnd();
}
}
示例8: State
public void State()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonWriter(sw))
{
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
jsonWriter.WriteStartObject();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WritePropertyName("CPU");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WriteValue("Intel");
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WritePropertyName("Drives");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WriteStartArray();
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteValue("DVD read/writer");
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteEnd();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WriteEndObject();
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
}
}
示例9: Indenting
public void Indenting()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("CPU");
jsonWriter.WriteValue("Intel");
jsonWriter.WritePropertyName("PSU");
jsonWriter.WriteValue("500W");
jsonWriter.WritePropertyName("Drives");
jsonWriter.WriteStartArray();
jsonWriter.WriteValue("DVD read/writer");
jsonWriter.WriteComment("(broken)");
jsonWriter.WriteValue("500 gigabyte hard drive");
jsonWriter.WriteValue("200 gigabype hard drive");
jsonWriter.WriteEnd();
jsonWriter.WriteEndObject();
}
string expected = @"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}";
string result = sb.ToString();
Console.WriteLine("Indenting");
Console.WriteLine(result);
Assert.AreEqual(expected, result);
}