本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteEnd方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteEnd方法的具体用法?C# JsonWriter.WriteEnd怎么用?C# JsonWriter.WriteEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteEnd方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.Formatting = Newtonsoft.Json.Formatting.Indented;
writer.WritePropertyName("ObjectId");
writer.WriteValue(((ObjectId) value).ToString());
writer.WriteEnd();
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var la = (IGroup)value;
writer.WriteStartObject();
writer.WritePropertyName("name");
writer.WriteValue(la.Name);
writer.WritePropertyName("lights");
serializer.Serialize(writer, la.Lights);
writer.WriteEnd();
}
示例3: WriteProperties
internal void WriteProperties(JsonWriter jsonWriter)
{
var properties = this._type.GetProperties();
foreach (var p in properties)
{
var att = ElasticAttributes.Property(p);
if (att != null && att.OptOut)
continue;
var propertyName = this.Infer.PropertyName(p);
var type = GetElasticSearchType(att, p);
if (type == null) //could not get type from attribute or infer from CLR type.
continue;
jsonWriter.WritePropertyName(propertyName);
jsonWriter.WriteStartObject();
{
if (att == null) //properties that follow can not be inferred from the CLR.
{
jsonWriter.WritePropertyName("type");
jsonWriter.WriteValue(type);
//jsonWriter.WriteEnd();
}
if (att != null)
this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type);
if (type == "object" || type == "nested")
{
var deepType = p.PropertyType;
var deepTypeName = this.Infer.TypeName(deepType);
var seenTypes = new ConcurrentDictionary<Type, int>(this.SeenTypes);
seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++i);
var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes);
var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes();
jsonWriter.WritePropertyName("properties");
nestedProperties.WriteTo(jsonWriter);
}
}
jsonWriter.WriteEnd();
}
}
示例4: HandleError
private void HandleError(JsonWriter writer, int initialDepth)
{
this.ClearErrorContext();
if (writer.WriteState == WriteState.Property)
writer.WriteNull();
while (writer.Top > initialDepth)
writer.WriteEnd();
}
示例5: 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);
}
示例6: 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);
}
}
示例7: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var document = value as DocumentRevision;
writer.WriteStartObject();
if (!string.IsNullOrEmpty(document.docId))
{
writer.WritePropertyName("_id");
serializer.Serialize(writer, document.docId);
}
if (!string.IsNullOrEmpty(document.revId))
{
writer.WritePropertyName("_rev");
serializer.Serialize(writer, document.revId);
}
if (document.isDeleted)
{
writer.WritePropertyName("_deleted");
serializer.Serialize(writer, document.isDeleted);
}
foreach (var pair in document.body)
{
writer.WritePropertyName(pair.Key);
serializer.Serialize(writer, pair.Value);
}
writer.WriteEnd();
}