本文整理匯總了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();
}
}