当前位置: 首页>>代码示例>>C#>>正文


C# JsonData.SetJsonType方法代码示例

本文整理汇总了C#中JsonData.SetJsonType方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.SetJsonType方法的具体用法?C# JsonData.SetJsonType怎么用?C# JsonData.SetJsonType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonData的用法示例。


在下文中一共展示了JsonData.SetJsonType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addTokenToPolicy

        private static byte[] addTokenToPolicy(string policy, string token)
        {
            var json = JsonMapper.ToObject(new JsonReader(policy));
            var found = false;
            var conditions = json["conditions"];
            if (conditions != null && conditions.IsArray)
            {
                for (int i =0;i<conditions.Count;i++)
                {
                    JsonData cond = conditions[i];
                    if (cond.IsObject && cond[S3Constants.PostFormDataSecurityToken] != null)
                    {
                        cond[S3Constants.PostFormDataSecurityToken] = token;
                        found = true;
                    }
                }

                if (!found)
                {
                    var tokenCondition = new JsonData();
                    tokenCondition.SetJsonType(JsonType.Object);
                    tokenCondition[S3Constants.PostFormDataSecurityToken] = token;
                    conditions.Add(tokenCondition);
                }
            }

            return Encoding.UTF8.GetBytes(JsonMapper.ToJson(json).Trim());
        }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity,代码行数:28,代码来源:S3PostUploadSignedPolicy.cs

示例2: GetExamples

        public JsonData GetExamples(string operationName)
        {

            if (_documentRoot.PropertyNames.Contains(ExamplesKey) &&
                _documentRoot[ExamplesKey].IsObject &&
                _documentRoot[ExamplesKey].PropertyNames.Contains(operationName) &&
                _documentRoot[ExamplesKey][operationName].IsArray)
                return _documentRoot[ExamplesKey][operationName];
            
            var empty = new JsonData();
            empty.SetJsonType(JsonType.Array);
            return empty;
            
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:14,代码来源:Customizations.cs

示例3: addConditionsToPolicy

        private static byte[] addConditionsToPolicy(string policy, Dictionary<string, string> newConditions)
        {
            var json = JsonMapper.ToObject(new JsonReader(policy));

            var jsonConditions = json["conditions"];

            if (jsonConditions != null && jsonConditions.IsArray)
            {
                foreach (var newCond in newConditions)
                {
                    bool found = false;
                    for (int i = 0; i < jsonConditions.Count; i++)
                    {
                        JsonData jsonCond = jsonConditions[i];
                        if (jsonCond.IsObject && jsonCond[newCond.Key] != null)
                        {
                            jsonCond[newCond.Key] = newCond.Value;
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        var jsonCond = new JsonData();
                        jsonCond.SetJsonType(JsonType.Object);
                        jsonCond[newCond.Key] = newCond.Value;
                        jsonConditions.Add(jsonCond);
                    }
                }
            }
            return Encoding.UTF8.GetBytes(JsonMapper.ToJson(json).Trim());
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:31,代码来源:S3PostUploadSignedPolicy.cs

示例4: 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));
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:76,代码来源:CustomizationCompiler.cs


注:本文中的JsonData.SetJsonType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。