本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WritePropertyString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WritePropertyString方法的具体用法?C# JsonTextWriter.WritePropertyString怎么用?C# JsonTextWriter.WritePropertyString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WritePropertyString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteAsJson
public static void WriteAsJson([NotNull] this Item item, [NotNull] TextWriter writer, [CanBeNull] Action<TextWriter> writeInner = null)
{
var output = new JsonTextWriter(writer)
{
Formatting = Formatting.Indented
};
output.WriteStartObject();
output.WriteStartObject("Item");
output.WritePropertyString("Name", item.ItemName);
output.WritePropertyStringIf("Id", item.Uri.Guid.Format());
output.WritePropertyStringIf("Database", item.DatabaseName);
output.WritePropertyStringIf("Path", item.ItemIdOrPath);
output.WritePropertyStringIf("Template", item.TemplateIdOrPath);
output.WriteStartObject("Fields");
var sharedFields = item.Fields.Where(f => string.IsNullOrEmpty(f.Language) && f.Version == 0).ToList();
var unversionedFields = item.Fields.Where(f => !string.IsNullOrEmpty(f.Language) && f.Version == 0).ToList();
var versionedFields = item.Fields.Where(f => !string.IsNullOrEmpty(f.Language) && f.Version != 0).ToList();
foreach (var field in sharedFields)
{
if (string.Equals(field.TemplateField.Type, "Layout", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Renderings", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Final Renderings", StringComparison.OrdinalIgnoreCase))
{
var layout = "{" + field.Value + "}";
var jToken = layout.ToJToken();
jToken?.First.WriteTo(output);
continue;
}
output.WritePropertyString(field.FieldName, field.Value);
}
if (unversionedFields.Any())
{
output.WriteStartObject("Unversioned");
foreach (var language in unversionedFields.Select(f => f.Language).Distinct())
{
output.WriteStartObject(language);
foreach (var field in unversionedFields.Where(f => f.Language == language))
{
output.WritePropertyString(field.FieldName, field.Value);
}
output.WriteEndObject();
}
output.WriteEndObject();
}
if (versionedFields.Any())
{
output.WriteStartObject("Versioned");
foreach (var language in versionedFields.Select(f => f.Language).Distinct())
{
output.WriteStartObject(language);
foreach (var version in versionedFields.Where(f => f.Language == language).Select(f => f.Version).Distinct())
{
output.WriteStartObject(version.ToString());
foreach (var field in versionedFields.Where(f => f.Language == language && f.Version == version))
{
output.WritePropertyString(field.FieldName, field.Value);
}
output.WriteEndObject();
}
output.WriteEndObject();
}
output.WriteEndObject();
}
output.WriteEndObject();
if (writeInner != null)
{
writeInner(writer);
}
output.WriteEndObject();
output.WriteEndObject();
}