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


C# JsonTextWriter.Flush方法代码示例

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


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

示例1: ExecuteResult

		public override void ExecuteResult(ControllerContext context)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			var response = context.HttpContext.Response;

			response.ContentType = MimeTypes.GetByExtension("json");

			if (ContentEncoding != null)
			{
				response.ContentEncoding = ContentEncoding;
			}

			if (Data != null)
			{
				var writer = new JsonTextWriter(response.Output) { Formatting = Formatting };

				var serializer = JsonSerializer.Create(SerializerSettings);
				serializer.Serialize(writer, Data);

				writer.Flush();
			}
		}
开发者ID:smhinsey,项目名称:Euclid,代码行数:26,代码来源:JsonNetResult.cs

示例2: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (this.Data == null)
            {
                return;
            }
            var response = context.HttpContext.Response;

            response.ContentType = !String.IsNullOrEmpty(ContentType) ? ContentType : "application/json";

            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }

            Type type = this.Data.GetType();
            // Wrap Enumerables to avoid potential Json Hijacking.
            if (TypeHelper.TryWrappingForIEnumerableGenericOrSame(ref type))
            {
                this.Data = TypeHelper.GetTypeRemappingConstructor(type).Invoke(new object[] { this.Data });
            }

            using (JsonTextWriter jsonTextWriter = new JsonTextWriter(response.Output) { CloseOutput = false })
            {
                var serializer = JsonSerializer.Create(this.SerializerSettings);
                serializer.Serialize(jsonTextWriter, this.Data);
                jsonTextWriter.Flush();
            }
        }
开发者ID:dax70,项目名称:MvcJson.Net,代码行数:33,代码来源:JsonNetResult.cs

示例3: WriteTo

        public static void WriteTo(this SecsMessage msg, JsonTextWriter jwtr)
        {
            jwtr.WriteStartObject();

            jwtr.WritePropertyName(nameof(msg.S));
            jwtr.WriteValue(msg.S);

            jwtr.WritePropertyName(nameof(msg.F));
            jwtr.WriteValue(msg.S);

            jwtr.WritePropertyName(nameof(msg.ReplyExpected));
            jwtr.WriteValue(msg.ReplyExpected);

            jwtr.WritePropertyName(nameof(msg.Name));
            jwtr.WriteValue(msg.Name);

            if (msg.SecsItem != null)
            {
                jwtr.WritePropertyName(nameof(msg.SecsItem));
                msg.SecsItem.WriteTo(jwtr);
            }

            jwtr.WriteEndObject();

            jwtr.Flush();
        }
开发者ID:mkjeff,项目名称:secs4net,代码行数:26,代码来源:JsonExtension.cs

示例4: WriteSchedules

        private void WriteSchedules(IEnumerable<Schedule> schedules, string name)
        {
            var html = GrapicSchedule.GraphicSchedule;
            string json = null;

            var m = new MemoryStream();
            var t = new StreamWriter(m);
            var w = new JsonTextWriter(t);
            var s = new JsonSerializer();
            w.Formatting = Formatting.Indented;
            w.QuoteName = false;
            s.Serialize(w, schedules);
            w.Flush();
            m.Flush();
            m.Position = 0;
            var r = new StreamReader(m);
            json = r.ReadToEnd();
            t.Dispose();
            r.Dispose();


            var f = new FileStream(@"C:\Users\Stefan\SkyDrive\Modelljärnväg\Träffar\2016\Kil\Graf" + name + ".html", FileMode.Create);
            using (var sw = new StreamWriter(f, new UTF8Encoding()))
            {
                sw.Write(html.Replace("'%DATA%';", json));
            }
            f.Dispose();

        }
开发者ID:fjallemark,项目名称:TrainDispatch,代码行数:29,代码来源:GraphicalScheduleTests.cs

示例5: GetData

        public override void GetData(object target, Stream outgoingData)
        {
            try
            {
                ////using (var writer = new StreamWriter(outgoingData))
                //{
                //    var bin = new BinaryFormatter();
                //    bin.Serialize(outgoingData, target);
                //}

                StreamWriter writer = new StreamWriter(outgoingData);
                JsonTextWriter jsonWriter = new JsonTextWriter(writer);
                JsonSerializer ser = JsonSerializer.Create(new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects });
                ser.Serialize(jsonWriter, target);
                jsonWriter.Flush();

                //var serializer = new XmlSerializer(target.GetType());
                //serializer.Serialize(outgoingData, target);

                //var writer = new StreamWriter(outgoingData);
                //writer.WriteLine(target);
                //writer.Flush();
            }
            catch (Exception ex)
            { throw; }
        }
开发者ID:Dhinoja,项目名称:Arc,代码行数:26,代码来源:ListVisualizer.cs

示例6: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (JsonRequestBehavior == JsonRequestBehavior.DenyGet
                && String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.");
            }

            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = !string.IsNullOrEmpty(ContentType)
                                       ? ContentType
                                       : "application/json";

            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;

            if (Data != null)
            {
                var writer = new JsonTextWriter(response.Output) { Formatting = Formatting };
                var serializer = JsonSerializer.Create(SerializerSettings);
                serializer.Serialize(writer, Data);

                writer.Flush();
            }
        }
开发者ID:sdf333,项目名称:MVCDEMO,代码行数:29,代码来源:JsonNetResult.cs

示例7: SerializeMessage

        public static Message SerializeMessage(JObject json, Message previousMessage)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    using (JsonTextWriter jtw = new JsonTextWriter(sw))
                    {
                        json.WriteTo(jtw);
                        jtw.Flush();
                        sw.Flush();
                        Message result = Message.CreateMessage(MessageVersion.None, null, new RawBodyWriter(ms.ToArray()));
                        if (previousMessage != null)
                        {
                            result.Properties.CopyProperties(previousMessage.Properties);
                            result.Headers.CopyHeadersFrom(previousMessage.Headers);
                            previousMessage.Close();
                        }

                        result.Properties[JsonRpcConstants.JObjectMessageProperty] = json;
                        return result;
                    }
                }
            }
        }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:25,代码来源:JsonRpcHelpers.cs

示例8: JsonSerializePayload

        internal static string JsonSerializePayload(IEnumerable<KeyValuePair<string, object>> payload)
        {
            try
            {
                using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Newtonsoft.Json.Formatting.Indented, CloseOutput = false })
                {
                    jsonWriter.WriteStartObject();

                    foreach (var item in payload)
                    {
                        JsonWriteProperty(jsonWriter, item.Key, item.Value);
                    }

                    jsonWriter.WriteEndObject();
                    jsonWriter.Flush();
                    return writer.ToString();
                }
            }
            catch (JsonWriterException jwe)
            {
                SemanticLoggingEventSource.Log.EventEntrySerializePayloadFailed(jwe.ToString());

                var errorDictionary = new Dictionary<string, object>
                {
                    {
                        "Error",
                        string.Format(CultureInfo.CurrentCulture, Properties.Resources.JsonSerializationError, jwe.Message)
                    }
                };

                return JsonConvert.SerializeObject(errorDictionary, Newtonsoft.Json.Formatting.Indented);
            }
        }
开发者ID:DeHeerSoftware,项目名称:semantic-logging,代码行数:34,代码来源:EventEntryUtil.cs

示例9: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)

                throw new ArgumentNullException("context");

            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = !string.IsNullOrEmpty(ContentType)

              ? ContentType

              : "application/json";

            if (ContentEncoding != null)

                response.ContentEncoding = ContentEncoding;

            if (Data != null)
            {

                JsonTextWriter writer = new JsonTextWriter(response.Output) { Formatting = Formatting };

                JsonSerializer serializer = JsonSerializer.Create(SerializerSettings);

                serializer.Serialize(writer, Data);

                writer.Flush();

            }
        }
开发者ID:phonglam29305,项目名称:fqtd,代码行数:31,代码来源:JsonNetResult.cs

示例10: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
                String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Method is not allowed.");
            }

            HttpResponseBase response = context.HttpContext.Response;

            if (!String.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            else
            {
                response.ContentType = "application/json";
            }
            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }
            if (Data != null)
            {
                var writer = new JsonTextWriter(response.Output) {Formatting = Formatting};
                JsonSerializer serializer = JsonSerializer.Create(SerializerSettings);
                serializer.Serialize(writer, Data);
                writer.Flush();
            }
        }
开发者ID:jseee,项目名称:Perevorot,代码行数:34,代码来源:JsonNetResult.cs

示例11: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpResponseBase response = context.HttpContext.Response;
            if (base.ContentType == null || base.ContentType.Length == 0)
            {
                response.ContentType = "application/json";
            }
            else
            {
                response.ContentType = base.ContentType;
            }

            if (base.ContentEncoding != null)
            {
                response.ContentEncoding = base.ContentEncoding;
            }

            if (base.Data != null)
            {
                var writer = new JsonTextWriter(response.Output) { Formatting = Formatting };

                JsonSerializer serializer = JsonSerializer.Create(SerializerSettings);
                serializer.Serialize(writer, Data);

                writer.Flush();
            }
        }
开发者ID:gkpeng19,项目名称:MyFramework,代码行数:32,代码来源:JsonNetResult.cs

示例12: parameterFieldMapJson

        /// <summary>
        /// Convert parameter list to json object
        /// </summary>
        public static string parameterFieldMapJson(parameters parms, string ProjectID, string QueryID)
        {
            StringWriter sw = new StringWriter();
            JsonTextWriter json = new JsonTextWriter(sw);

            json.WriteStartObject();
            json.WritePropertyName("results");
            json.WriteStartArray();
            json.WriteStartObject();
            // ProjectID and QueryID
            json.WritePropertyName("ProjectID");
            json.WriteValue(ProjectID);
            json.WritePropertyName("QueryID");
            json.WriteValue(QueryID);

            json.WritePropertyName("parameters");
            json.WriteRawValue(JsonConvert.SerializeObject(parms));

            json.WriteEndObject();
            json.WriteEndArray();
            json.WriteEndObject();

            json.Flush();
            sw.Flush();

            return sw.ToString();
        }
开发者ID:kstubs,项目名称:ProjFlx,代码行数:30,代码来源:Helper.cs

示例13: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if(context == null)
                throw new ArgumentNullException("context");

            if(IsDebugEnabled)
                log.Debug(
                    "Action 처리결과를 Newtonsoft.Json의 JsonSerializer를 이용하여, 직렬화하여 HttpResponse에 씁니다... Result=[{0}]",
                    Result);

            if(Result == null)
                return;

            var response = context.HttpContext.Response;

            if(ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;

            response.ContentType = string.IsNullOrWhiteSpace(ContentType) ? MvcTool.JsonContentType : ContentType;

            using(var writer = new JsonTextWriter(response.Output) { Formatting = this.Formatting })
            {
                var serializer = JsonSerializer.Create(SerializerSettings);
                serializer.Serialize(writer, Result);

                writer.Flush();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:28,代码来源:JsonNetResult.cs

示例14: SerializeError_serializes_httperror

        public void SerializeError_serializes_httperror()
        {
            using (var stream = new MemoryStream())
            {
                var textWriter = new StreamWriter(stream);
                var writer = new JsonTextWriter(textWriter);

                var mockInnerException = new Mock<Exception>(MockBehavior.Strict);
                mockInnerException.Setup(m => m.Message).Returns("Inner exception message");
                mockInnerException.Setup(m => m.StackTrace).Returns("Inner stack trace");

                var outerException = new Exception("Outer exception message", mockInnerException.Object);

                var error = new HttpError(outerException, true)
                {
                    StackTrace = "Outer stack trace"
                };
                var jsonSerializer = new JsonSerializer();

                var mockIdProvider = new Mock<IErrorIdProvider>(MockBehavior.Strict);
                mockIdProvider.SetupSequence(p => p.GenerateId(It.IsAny<HttpError>())).Returns("OUTER-ID").Returns("INNER-ID");

                var serializer = new ErrorSerializer(mockIdProvider.Object);
                serializer.SerializeError(error, stream, writer, jsonSerializer);

                writer.Flush();

                var expectedJson = File.ReadAllText("ErrorSerializerTest.json");
                var minifiedExpectedJson = JsonHelpers.MinifyJson(expectedJson);
                var output = System.Text.Encoding.ASCII.GetString(stream.ToArray());
                output.Should().Be(minifiedExpectedJson);
            }
        }
开发者ID:Eclarian,项目名称:JSONAPI.NET,代码行数:33,代码来源:ErrorSerializerTests.cs

示例15: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (this.JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
                string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("To allow GET requests, set JsonRequestBehavior to AllowGet.");
            }

            if (this.Data == null)
                return;

            var response = context.HttpContext.Response;
            response.ContentType = string.IsNullOrEmpty(this.ContentType) ? "application/json" : this.ContentType;

            if (this.ContentEncoding != null)
                response.ContentEncoding = this.ContentEncoding;

            var serializer = JsonSerializer.Create(this.Settings);
            using (var writer = new JsonTextWriter(response.Output))
            {
                serializer.Serialize(writer, Data);
                writer.Flush();
            }
        }
开发者ID:rabbal,项目名称:AspNetMVCNTierTemp,代码行数:27,代码来源:JsonNetResult.cs


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