本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteRequiredValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteRequiredValue方法的具体用法?C# JsonTextWriter.WriteRequiredValue怎么用?C# JsonTextWriter.WriteRequiredValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteRequiredValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save()
{
using (var stream = FileSystem.Current.GetFile(FileSystem.Combine(Resources.GameUserDir, SettingsFile)).OpenStream(FileMode.Create))
{
using (var textWriter = new StreamWriter(stream))
{
using (JsonWriter writer = new JsonTextWriter(textWriter))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
writer.WritePropertyName("game");
writer.WriteStartObject();
writer.WriteRequiredValue("uid", Settings.GameUid);
if (Settings.StatisticsServiceEnabled.HasValue)
{
writer.WritePropertyName("statisticsserviceenabled");
writer.WriteValue(Settings.StatisticsServiceEnabled.Value);
}
writer.WriteRequiredValue("username", Settings.UserName ?? string.Empty);
writer.WriteRequiredValue("passwordhash",DPAPI.Encrypt(Settings.Password ?? string.Empty));
writer.WriteEndObject();
writer.WriteEndObject();
}
}
}
}
示例2: CreateUpdateFileData
public static byte[] CreateUpdateFileData(UpdateDetails details, List<string> removeFiles)
{
using (var stream = new MemoryStream())
{
using (var textWriter = new StreamWriter(stream))
{
using (JsonWriter writer = new JsonTextWriter(textWriter))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
writer.WriteRequiredValue("updateminversion", details.UpdateVersion.ToString());
writer.WriteRequiredValue("updatemaxversion", details.UpdateVersion.ToString());
writer.WritePropertyName("removefiles");
writer.WriteStartArray();
foreach (var file in removeFiles)
{
writer.WriteValue(file);
}
writer.WriteEndArray();
writer.WriteEndObject();
}
}
return stream.ToArray();
}
}