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


C# JsonWriter.Flush方法代码示例

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


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

示例1: FromHashtableQueue

 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     UUIDConverter UUID = new UUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         try
         {
             Hashtable hashtable = queue.Dequeue();
             serializer.Serialize(jsonWriter, hashtable);
         }
         catch(Exception e)
         {
             AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
         }
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
开发者ID:AlphaStaxLLC,项目名称:AjaxLife,代码行数:27,代码来源:MakeJson.cs

示例2: JsonResponse

        public static void JsonResponse(HttpResponse response, Action<JsonWriter> writeAction)
        {
            response.ClearHeaders();
            response.ClearContent();

            JsonWriter writer = new JsonWriter(response.Output);

            writeAction(writer);

            writer.Flush();
        }
开发者ID:mrkurt,项目名称:mubble-old,代码行数:11,代码来源:JsonHandler.cs

示例3: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("value");
            writer.WriteValue((value).ToString());

            writer.WriteEndObject();

            writer.Flush();
        }
开发者ID:nhsevidence,项目名称:Snooze,代码行数:11,代码来源:UrlConverter.cs

示例4: FromObject

 public static string FromObject(object obj)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     serializer.Serialize(jsonWriter, obj);
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
开发者ID:cfire24,项目名称:ajaxlife,代码行数:14,代码来源:MakeJson.cs

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var products = (List<Product>)value;

            foreach (var product in products)
            {
                writer.WriteStartObject();

                writer.WritePropertyName(product.ProductSKU);
                writer.WriteRawValue(JsonConvert.SerializeObject(product.ProductData));

                writer.WriteEndObject();
            }

            writer.Flush();
        }
开发者ID:Soulfire86,项目名称:Yotpo.Net,代码行数:16,代码来源:YotpoProductsJsonConverter.cs

示例6: FromHashtableQueue

 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         Hashtable hashtable = queue.Dequeue();
         serializer.Serialize(jsonWriter, hashtable);
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
开发者ID:cfire24,项目名称:ajaxlife,代码行数:20,代码来源:MakeJson.cs

示例7: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                serializer.Serialize(writer, null);
                return;
            }

            //Get all the properties that contain either the CopernicaField of the CopernicaKeyField attribute.
            var properties = value.GetType().GetProperties().Where(x => x.GetCustomAttributes(false).Any(y => y.GetType() == typeof(CopernicaField) || y.GetType() == typeof(CopernicaKeyField)));
            
            //Loop through the properties and add the CopernicaField name + property value to the JObject.
            //This makes sure the mapping is right when serializing the object.
            JObject obj = new JObject();
            foreach (var property in properties)
            {
                obj.Add(property.GetCustomAttribute<CopernicaField>().Name, property.GetValue(value) == null ? "" : property.GetValue(value).ToString());
            }
            obj.WriteTo(writer);

            writer.Flush();
        }
开发者ID:Atzie,项目名称:CopernicaNET,代码行数:22,代码来源:JsonFieldsConverter.cs

示例8: Serialize

        public Task Serialize(IResourceCollectionDocument document, JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(PrimaryDataKeyName);

            writer.WriteStartArray();
            foreach (var resourceObject in document.PrimaryData)
            {
                _resourceObjectFormatter.Serialize(resourceObject, writer);
            }
            writer.WriteEndArray();

            if (document.RelatedData != null && document.RelatedData.Any())
            {
                writer.WritePropertyName(RelatedDataKeyName);
                writer.WriteStartArray();
                foreach (var resourceObject in document.RelatedData)
                {
                    _resourceObjectFormatter.Serialize(resourceObject, writer);
                }
                writer.WriteEndArray();
            }

            if (document.Metadata != null)
            {
                writer.WritePropertyName(MetaKeyName);
                _metadataFormatter.Serialize(document.Metadata, writer);
            }

            writer.WriteEndObject();

            writer.Flush();

            return Task.FromResult(0);
        }
开发者ID:BradBarnich,项目名称:JSONAPI.NET,代码行数:36,代码来源:ResourceCollectionDocumentFormatter.cs

示例9: OnFileRequested

        public void OnFileRequested(HttpRequest request, IDirectory directory)
        {
            request.Response.ResponseContent = new MemoryStream();
            StreamWriter writer = new StreamWriter(request.Response.ResponseContent);
            try
            {
                StreamReader reader = new StreamReader(request.PostData);
                string post = reader.ReadToEnd();
                reader.Dispose();
                // Decode the POST data.
                Dictionary<string,string> POST = deviMobile.PostDecode(post);
                Guid session = new Guid(POST["sid"]);
                Events eventqueue;
                User user;
                GridClient client;
                // Load in the session data.
                lock (users)
                {
                    user = users[session];
                    eventqueue = user.Events;
                    client = user.Client;
                    user.LastRequest = DateTime.Now;
                }
                bool sent = false;
                double heading = user.Rotation;
                // Check once per second, timing out after 15 seconds.
                for (int i = 0; i < 5; ++i)
                {
                    // Ugly hack - we're riding on the back of the event poll to rotate our camera.
                    if(user.Rotation != -4)
                    {
                        // If we've reached π, having started at -π, we're done. Quit rotating, because it
                        // appears to annoy people and/or make them dizzy.
                        heading += 0.5d;
                        if (heading > Math.PI)
                        {
                            // We use -4 because -4 < -π, so will never occur during normal operation.
                            user.Rotation = -4;
                            heading = Math.PI;
                            // Reset the draw distance to attempt to reduce traffic. Also limits the
                            // nearby list to people within chat range.
                            user.Client.Self.Movement.Camera.Far = 20.0f;
                            user.Client.Self.Movement.SendUpdate();
                        }
                        else
                        {
                            user.Rotation = heading;
                        }
                        client.Self.Movement.UpdateFromHeading(heading, false);
                    }

                    if (eventqueue.GetEventCount() > 0)
                    {
                        writer.WriteLine(eventqueue.GetPendingJson(client));
                        sent = true;
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                // If nothing of interest ever came up, we just send the standard footer.
                if (!sent)
                {
                    JsonWriter w = new JsonWriter(writer);
                    w.WriteStartArray();
                    (new JsonSerializer()).Serialize(w, eventqueue.GetFooter(client));
                    w.WriteEndArray();
                    w.Flush();
                }
            }
            catch (Exception e)
            {
                request.Response.ContentType = "text/plain";
                writer.WriteLine(e.Message);
            }
            writer.Flush();
        }
开发者ID:deviSAS,项目名称:j2me-client,代码行数:79,代码来源:EventQueue.cs

示例10: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteValue(Convert.ToDateTime(value).AddMinutes(_timeZoneOffset).ToString(_dateFormat));
     writer.Flush();
 }
开发者ID:kidaa,项目名称:Indigo,代码行数:5,代码来源:JSONCustomDateConverter.cs

示例11: WriteJson

        /// <summary>The write json.</summary>
        /// <param name="writer">The writer.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null)
            {
                return;
            }

            var row = value as OrderRow;
            if (row == null)
            {
                return;
            }

            writer.WriteStartArray();
            writer.WriteRawValue(row.Price.ToInvariantString(2));
            writer.WriteRawValue(row.VolRemaining.ToInvariantString());
            writer.WriteRawValue(row.Range.ToInvariantString());
            writer.WriteRawValue(row.OrderId.ToInvariantString());
            writer.WriteRawValue(row.VolEntered.ToInvariantString());
            writer.WriteRawValue(row.MinVolume.ToInvariantString());
            writer.WriteRawValue(row.Bid.ToInvariantString());
            writer.WriteValue(row.IssueDate);
            writer.WriteRawValue(row.Duration.ToInvariantString());
            writer.WriteRawValue(row.StationId.ToInvariantString());
            writer.WriteRawValue(row.SolarSystemId.ToInvariantString());
            writer.WriteEndArray();

            writer.Flush();
        }
开发者ID:itguy327,项目名称:EveHQ,代码行数:33,代码来源:OrderRowConverter.cs

示例12: GenerateJsonSchema

        private string GenerateJsonSchema()
        {
            List<string> required = new List<string>();
            MemoryStream stream = new MemoryStream();
            JsonWriter writer = new JsonWriter(stream);
            writer.WriteObject();

            writer.WriteMember("$schema");
            writer.WriteValue("http://json-schema.org/draft-04/schema");

            writer.WriteMember("title");
            writer.WriteValue(Object.Name);

            writer.WriteMember("type");
            writer.WriteValue("object");

            writer.WriteMember("properties");

            AddJsonProperties(writer, Object.GetProperties(), false);

            if (required.Count > 0)
            {
                writer.WriteMember("required");
                writer.WriteArray();
                foreach (string requirement in required)
                {
                    writer.WriteValue(requirement);
                }
                writer.WriteEndArray();
            }

            writer.WriteEndObject();

            writer.Flush();
            stream.Position = 0;

            string unformattedJsonBody = new StreamReader(stream).ReadToEnd();
            object parsedJson = JsonConvert.DeserializeObject(unformattedJsonBody);
            return JsonConvert.SerializeObject(parsedJson, Newtonsoft.Json.Formatting.Indented);
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:40,代码来源:Schema.cs

示例13: WriteJson

         public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
         {
            var searchResult = (CourseCatalogSearchResult)value;
            var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
            writer.WriteStartObject();

            writer.WritePropertyName("draw");
            writer.WriteValue(searchResult.draw);

            writer.WritePropertyName("recordsTotal");
            writer.WriteValue(searchResult.recordsTotal);

            writer.WritePropertyName("recordsFiltered");
            writer.WriteValue(searchResult.recordsFiltered);

            writer.WritePropertyName("catalog");
            writer.WriteStartArray();
            foreach (var entry in searchResult.catalog)
            {
               writer.WriteStartObject();

               writer.WritePropertyName("trainingProvider");
               var trainingProviderHtmlString =
                  string.Format("<a href='{0}'><img width='75' src='{1}' alt='{2}' /></a>",
                     urlHelper.RouteUrl(AppConstants.RouteNames.TrainingProvider, entry.TrainingProvider.TrainingProviderRouteValuesObject),
                     entry.TrainingProvider.LogoUrl,
                     entry.TrainingProvider.Name);
               writer.WriteValue(trainingProviderHtmlString);

               writer.WritePropertyName("category");
               var categoryHtmlString =
                  string.Format("<a href='{0}'>{1}</a>",
                     urlHelper.RouteUrl(AppConstants.RouteNames.TrainingProviderCategory, entry.Category.CategoryRouteValuesObject),
                     entry.Category.Title);
               writer.WriteValue(categoryHtmlString);

               writer.WritePropertyName("courseTitle");
               var courseTitleHtmlString =
                  string.Format("<span>{0}{1}<a href='{2}'>{3}</a>{4}</span>",
                     HtmlHelperExtensions.GetCourseSubscriptionMarker(entry.Course.LearningState).ToString(),
                     "&nbsp;",
                     urlHelper.RouteUrl(AppConstants.RouteNames.Course, entry.CourseRouteValueObject),
                     entry.Course.Title,
                     entry.Course.HasClosedCaptions ? "&nbsp;<i class='text-info fa fa-cc'></i>" : null);
               writer.WriteValue(courseTitleHtmlString);

               writer.WritePropertyName("authors");
               var authorsHtmlString = HtmlHelperExtensions.GetCourseAuthors(entry.TrainingProvider.Name,
                  entry.Course.Authors);
               writer.WriteValue(authorsHtmlString.ToString());

               writer.WritePropertyName("level");
               writer.WriteValue(entry.Course.Level.ToString());

               writer.WritePropertyName("duration");
               var durationHtmlString = string.Format("<span>{0}<small>h</small>&nbsp;{1}<small>m</small></span>",
                  entry.Course.Duration.Hours, entry.Course.Duration.Minutes);
               writer.WriteValue(durationHtmlString);

               writer.WritePropertyName("releaseDate");
               var releaseDateString = entry.Course.ReleaseDate.ToString("yyyy-MM-dd");
               writer.WriteValue(releaseDateString);

               writer.WritePropertyName("rating");
               var ratingHtmlString = HtmlHelperExtensions.GetCourseRating(entry.Course.Rating);
               writer.WriteValue(ratingHtmlString.ToString());

               writer.WriteEndObject();
            }
            writer.WriteEndArray();

            writer.WriteEndObject();

            writer.Flush();
         }
开发者ID:ssh-git,项目名称:training-manager,代码行数:75,代码来源:CourseViewModels.cs

示例14: WriteJson

 public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer )
 {
     writer.WriteValue( Enum.GetName( value.GetType(), value ) );
     writer.Flush();
 }
开发者ID:hvitorino,项目名称:iTunes-Library,代码行数:5,代码来源:ConversorDeEnumeracoes.cs

示例15: WriteJson

 /// <summary>
 /// Método de escrito de objetos JSon
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="value"></param>
 /// <param name="serializer"></param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteValue(((DateTime)value).ToString("dd/MM/yyyy"));
     writer.Flush();
 }
开发者ID:payu-br,项目名称:bcash-dotnet-sdk,代码行数:11,代码来源:DateTimeConverter.cs


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