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


C# JsonData.ToString方法代码示例

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


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

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            string json = null;
            using (Stream stream = context.Request.InputStream)
            {
                StreamReader reader = new StreamReader(stream);
                json = reader.ReadToEnd();
            }

            // load...
            JsonData input = new JsonData(json);
            JsonData output = new JsonData();
            try
            {
                DoRequest(input, output);

                // did we get output?
                if (!(output.ContainsKey("isOk")))
                    output["isOk"] = true;
            }
            catch(Exception ex)
            {
                output["isOk"] = false;
                output["error"] = "General failure.";
                output["generalFailure"] = ex.ToString();
            }

            // jqm access control bits...
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            context.Response.AddHeader("Access-Control-Allow-Methods", "POST, GET");

            // send...
            context.Response.ContentType = "text/json";
            context.Response.Write(output.ToString());
        }
开发者ID:mbrit,项目名称:dotnet-streetfoo,代码行数:35,代码来源:AjaxHandler.cs

示例2: GetSampleLiteral

        /// <summary>
        /// Given a Shape and sample data, build a literal/instantiation for the
        /// Shape's type with the sample data.
        /// </summary>
        /// <param name="shape">The Shape in the model</param>
        /// <param name="data">Sample data to populate the literal with</param>
        /// <param name="cb">A CodeBuilder instance to write the code to.</param>
        public void GetSampleLiteral(Shape shape, JsonData data, CodeBuilder cb)
        {
            if (shape.IsString && data.IsString)
                cb.AppendQuote(data.ToString());
            if (shape.IsBoolean)
                cb.Append(data.ToString().ToLower());
            if (shape.IsFloat || shape.IsInt || shape.IsDouble || shape.IsLong)
                cb.Append(data.ToString());

            if (shape.IsList && data.IsArray)
            {
                var itemType = shape.ListShape;

                cb.AppendFormat("new List<{0}> ", ShapeType(itemType)).OpenBlock();

                for (int i = 0; i < data.Count; i++)
                {
                    GetSampleLiteral(itemType, data[i], cb);
                    if (i < (data.Count - 1))
                        cb.AppendLine(",");
                }

                cb.CloseBlock();
            }

            if (shape.IsMap && data.IsObject)
            {
                var keyType = shape.KeyShape;
                var valType = shape.ValueShape;

                cb.AppendFormat("new Dictionary<{0}, {1}> ", ShapeType(keyType), ShapeType(valType));

                cb.OpenBlock();

                foreach (var k in data.PropertyNames)
                {
                    cb.Append("{ ");

                    GetSampleLiteral(keyType, k, cb);
                    cb.Append(", ");
                    GetSampleLiteral(valType, data[k], cb);

                    cb.Append(" }");
                    if (k != data.PropertyNames.Last())
                        cb.AppendLine(",");
                }

                cb.CloseBlock();

            }

            if (shape.IsStructure && data.IsObject)
            {
                cb.AppendFormat("new {0} ", ShapeType(shape));

                if (data.PropertyNames.Count() > 1)
                    cb.OpenBlock();
                else
                    cb.Append("{ ");

                foreach (var field in data.PropertyNames)
                {
                    var property = shape.Members.GetMemberByName(field);
 
                    if (null == property)
                        continue;

                    cb.AppendFormat("{0} = ", property.PropertyName);
                    GetSampleLiteral(property, data[field], cb);

                    if (field != data.PropertyNames.Last())
                        cb.AppendLine(",");

                }

                if (data.PropertyNames.Count() > 1)
                    cb.CloseBlock();
                else
                    cb.Append(" }");
            }
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:88,代码来源:Example.cs


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