當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。