本文整理汇总了C#中JsonData.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.ToJson方法的具体用法?C# JsonData.ToJson怎么用?C# JsonData.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonData
的用法示例。
在下文中一共展示了JsonData.ToJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInstructionFileRequest
internal static PutObjectRequest CreateInstructionFileRequest(AmazonWebServiceRequest request, EncryptionInstructions instructions)
{
byte[] keyBytesToStoreInInstructionFile = instructions.EncryptedEnvelopeKey;
string base64EncodedEnvelopeKey = Convert.ToBase64String(keyBytesToStoreInInstructionFile);
byte[] IVToStoreInInstructionFile = instructions.InitializationVector;
string base64EncodedIV = Convert.ToBase64String(IVToStoreInInstructionFile);
JsonData jsonData = new JsonData();
jsonData["EncryptedEnvelopeKey"] = base64EncodedEnvelopeKey;
jsonData["IV"] = base64EncodedIV;
string credentials = jsonData.ToJson();
var putObjectRequest = request as PutObjectRequest;
if (putObjectRequest != null)
{
PutObjectRequest requestforInstructionFile = new PutObjectRequest()
{
BucketName = putObjectRequest.BucketName,
Key = putObjectRequest.Key + instructionfileSuffix,
ContentBody = credentials
};
requestforInstructionFile.Metadata.Add(instructionFileInfo, "");
return requestforInstructionFile;
}
var completeMultiPartRequest = request as CompleteMultipartUploadRequest;
if (completeMultiPartRequest != null)
{
PutObjectRequest requestforInstructionFile = new PutObjectRequest()
{
BucketName = completeMultiPartRequest.BucketName,
Key = completeMultiPartRequest.Key + instructionfileSuffix,
ContentBody = credentials
};
requestforInstructionFile.Metadata.Add(instructionFileInfo, "");
return requestforInstructionFile;
}
else
return null;
}
示例2: CompileServiceCustomizations
/// <summary>
/// Compiles all files in the namespace *.customizations*.json into one large json file in bin\Release|Debug\customizations folder
/// </summary>
/// <param name="modelsPath">The path the to customization models to be compiled</param>
public static void CompileServiceCustomizations(string modelsPath)
{
Console.WriteLine("Compiling service customizations from {0}", modelsPath);
if (Directory.Exists("customizations"))
{
Console.WriteLine("...cleaning previous compilation output");
// Cleanup any previous run customization.
foreach (var file in Directory.GetFiles("customizations"))
{
File.Delete(file);
}
}
else
{
Directory.CreateDirectory("customizations");
}
var fileServices = Directory.GetFiles(modelsPath, "*.customizations*.json");
foreach (var file in fileServices)
{
// The name before the .customizations extension
// Used to get all files for that service
var baseName = file.Substring(file.IndexOf("ServiceModels"+Path.DirectorySeparatorChar , StringComparison.OrdinalIgnoreCase)
+ ("ServiceModels"+Path.DirectorySeparatorChar).Length, file.IndexOf(".customizations", StringComparison.OrdinalIgnoreCase)
- Convert.ToInt32(file.IndexOf("ServiceModels"+Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)
+ ("ServiceModels"+Path.DirectorySeparatorChar).Length));
var filePath = Path.Combine("customizations", baseName + ".customizations.json");
var fileEntries = Directory.GetFiles(modelsPath, baseName + "*.customizations*.json");
var jsonWriter = new JsonWriter {PrettyPrint = true};
JsonData outputJson = new JsonData();
outputJson.SetJsonType(JsonType.Object);
foreach (var entry in fileEntries)
{
var customJson = JsonMapper.ToObject(new StreamReader(entry));
foreach (var property in customJson.PropertyNames)
{
outputJson[property] = customJson[property];
}
}
// Load examples into the customizations as well
var examples = Directory.GetFiles(modelsPath, baseName + ".examples.json").FirstOrDefault();
if (null != examples)
{
var exampleData = JsonMapper.ToObject(new StreamReader(examples));
if (exampleData.IsObject && exampleData.PropertyNames.Contains("examples"))
{
outputJson["examples"] = exampleData["examples"];
}
}
outputJson.ToJson(jsonWriter);
// Fixes json being placed into the json mapper
var output = jsonWriter.ToString();
// Empty json file
if (output.Length < 10)
continue;
File.WriteAllText(filePath, output);
Console.WriteLine("...updated {0}", Path.GetFullPath(filePath));
}
}