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


C# JsonWriter.WriteRaw方法代码示例

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


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

示例1: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			ElasticQuery term = (ElasticQuery)value;
			if (term != null)
			{
				writer.WriteStartObject();

				writer.WriteRaw("\"from\": " + term.From);
				writer.WriteRaw(",\"size\": " + term.Size + ",");
				writer.WritePropertyName("query");
				serializer.Serialize(writer, term.Query);

				if (term.Fields != null && term.Fields.Count > 0)
				{
					writer.WritePropertyName("fields");
					writer.WriteStartArray();
					foreach (var field in term.Fields)
					{
						writer.WriteRawValue("\"" + field + "\"");
					}
					writer.WriteEndArray();
				}
				if (term.SortItems != null && term.SortItems.Count > 0)
				{
					writer.WritePropertyName("sort");
					writer.WriteStartObject();
					foreach (var sortItem in term.SortItems)
					{
					    if (sortItem != null)
					    {
					        writer.WritePropertyName(sortItem.FieldName);
					        writer.WriteValue(sortItem.SortType.ToString().ToLower());
					    }
					}

					writer.WriteEndObject();
				}

                //facets
                if (term.Facets != null)
                {
                    writer.WritePropertyName("facets");
                    serializer.Serialize(writer, term.Facets);
                }

                //hightlight
                if(term.Hightlight!=null)
                {
                    writer.WritePropertyName("highlight");
                    serializer.Serialize(writer,term.Hightlight);
                }

                if (term.Explain)
                {
                    writer.WriteRaw(",\"explain\": " + term.Explain.ToString().ToLower());
                }

				writer.WriteEndObject();
			}
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:60,代码来源:ElasticQueryConverter.cs

示例2: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var filterList = value as FilterList;
            if (filterList == null) throw new InvalidOperationException("FilterListConverter attribute is not applied to FilterList class");

            if(filterList.Data.Count == 1)
            {
                writer.WriteRaw(JsonConvert.SerializeObject(filterList.Data[0]));
            }
            else
            {
                writer.WriteRaw(JsonConvert.SerializeObject(new FilterGroup(filterList.Data)));
            }
        }
开发者ID:aforty,项目名称:factual-csharp-driver,代码行数:14,代码来源:FilterListConverter.cs

示例3: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var filter = value as Filter;
            if(filter == null) throw new InvalidOperationException("FilterConverter attribute is not applied to Filter class");

            if(filter.Value is bool) //lowercase boolean values
            {
                writer.WriteRaw(filter.Value.ToString().ToLower());
            }
            else
            {
                writer.WriteRaw(filter.Value.ToString());
            }
        }
开发者ID:kmc059000,项目名称:factual-csharp-driver,代码行数:14,代码来源:FilterConverter.cs

示例4: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = value as IMultiPercolateRequest;
			if (request == null) return;
			if (request.Percolations == null) return;

			var settings = serializer.GetConnectionSettings();
			var elasticsearchSerializer = settings.Serializer;
			if (elasticsearchSerializer == null) return;
			foreach (var percolation in request.Percolations)
			{
				var requestParameters = percolation.GetRequestParameters() ?? new PercolateRequestParameters();
				var header = new PercolateHeader
				{
					percolate_index = requestParameters.GetQueryStringValue<string>("percolate_index"),
					percolate_type = requestParameters.GetQueryStringValue<string>("percolate_type"),
					routing = requestParameters.GetQueryStringValue<string[]>("routing"),
					preference = requestParameters.GetQueryStringValue<string>("preference"),
					percolate_routing = requestParameters.GetQueryStringValue<string>("percolate_routing"),
					percolate_preference = requestParameters.GetQueryStringValue<string>("percolate_preference"),
					version = requestParameters.GetQueryStringValue<long?>("version")
				};
				var routeValues = (percolation as IRequest)?.RouteValues;
				if (routeValues != null)
				{
					header.id = routeValues.Get<Id>("id");
					header.index = routeValues.Get<IndexName>("index");
					header.type = routeValues.Get<TypeName>("type");
					if (request.Index != null && request.Index.EqualsMarker(header.index)) header.index = null;
					if (request.Type != null && request.Type.EqualsMarker(header.type)) header.type = null;
				}
				var headerBytes = elasticsearchSerializer.SerializeToBytes(header, SerializationFormatting.None);
				writer.WriteRaw($"{{\"{percolation.MultiPercolateName}\":" + headerBytes.Utf8String() + "}\n");
				if (percolation == null)
				{
					writer.WriteRaw("{}\n");
				}
				else
				{
					var bodyBytes = elasticsearchSerializer.SerializeToBytes(percolation, SerializationFormatting.None);
					writer.WriteRaw(bodyBytes.Utf8String() + "\n");
				}
			}
		}
开发者ID:jeroenheijmans,项目名称:elasticsearch-net,代码行数:44,代码来源:MultiPercolateJsonConverter.cs

示例5: Serialize

        /// <exception cref="ArgumentNullException">when <paramref name="writer"/> is null</exception>
        /// <exception cref="ArgumentNullException">when <paramref name="value"/> is null</exception>
        public new void Serialize(JsonWriter writer, object value)
        {
            if (writer == null) throw new ArgumentNullException("writer");
            if (value == null) throw new ArgumentNullException("value");

            if( ReflectionUtilities.Implements(value.GetType(), typeof(ISerializableToJavaScript)) && !customSerializationObjects.Contains(value) )
            {
                customSerializationObjects.Add(value);
                ((ISerializableToJavaScript) value).SerializeToJavaScript(this, writer);
                customSerializationObjects.Remove(value);
                return;
            }

            var attribute = ReflectionUtilities.GetAttribute<JavaScriptObjectAttribute>(value);

            if( attribute != null && !string.IsNullOrEmpty(attribute.Prefix) ) writer.WriteRaw(attribute.Prefix);

            base.Serialize(writer, value);

            if( attribute != null && !string.IsNullOrEmpty(attribute.Suffix) ) writer.WriteRaw(attribute.Suffix);
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:23,代码来源:JavaScriptSerializer.cs

示例6: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = value as IMultiSearchRequest;
			if (request == null) return;
			var settings = serializer.GetConnectionSettings();
			var elasticsearchSerializer = settings.Serializer;
			if (elasticsearchSerializer == null) return;

			if (request.Operations == null) return;

			foreach (var operation in request.Operations.Values)
			{
				var indices = (request.Index != null && !request.Index.Equals(operation.Index))
					? operation.Index
					: null;

				var types = (request.Type != null && !request.Type.Equals(operation.Type))
					? operation.Type
					: null;

				var searchType = operation.RequestParameters.GetQueryStringValue<SearchType>("search_type").GetStringValue();
				if (searchType == "query_then_fetch")
					searchType = null;

				var header = new
				{
					index = (indices as IUrlParameter)?.GetString(settings),
					type = (types as IUrlParameter)?.GetString(settings),
					search_type = searchType,
					preference = operation.Preference,
					routing = operation.Routing,
					ignore_unavailable = operation.IgnoreUnavalable
				};

				var headerBytes = elasticsearchSerializer.SerializeToBytes(header, SerializationFormatting.None);
				writer.WriteRaw(headerBytes.Utf8String() + "\n");
				var bodyBytes = elasticsearchSerializer.SerializeToBytes(operation, SerializationFormatting.None);
				writer.WriteRaw(bodyBytes.Utf8String() + "\n");
			}
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:40,代码来源:MultiSearchJsonConverter.cs

示例7: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = (IMultiSearchTemplateRequest)value;
			if (request == null) return;
			var settings = serializer.GetConnectionSettings();
			var elasticsearchSerializer = settings.Serializer;
			if (elasticsearchSerializer == null) return;

			if (request.Operations == null) return;

			foreach (var operation in request.Operations.Values)
			{
				IUrlParameter indices = request.Index == null || !request.Index.Equals(operation.Index)
					? operation.Index
					: null;

				IUrlParameter types = request.Type == null || !request.Type.Equals(operation.Type)
					? operation.Type
					: null;

				var searchType = operation.RequestParameters.GetQueryStringValue<SearchType>("search_type").GetStringValue();
				if (searchType == "query_then_fetch")
					searchType = null;

				var header = new
				{
					index = indices?.GetString(settings),
					type = types?.GetString(settings),
					search_type = searchType,
					preference = operation.Preference,
					routing = operation.Routing,
					ignore_unavailable = operation.IgnoreUnavalable
				};

				var headerString = elasticsearchSerializer.SerializeToString(header, SerializationFormatting.None);
				writer.WriteRaw($"{headerString}\n");
				var bodyString = elasticsearchSerializer.SerializeToString(operation, SerializationFormatting.None);
				writer.WriteRaw($"{bodyString}\n");
			};
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:40,代码来源:MultiSearchTemplateJsonConverter.cs

示例8: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var tsr = value as TimeseriesResult;

            if(tsr == null)
                throw new InvalidOperationException("Cannot serialize type {0}".FormatString(value.GetType()));

            writer.WriteRaw(JsonConvert.SerializeObject(new {
                RollupType = tsr.RollupType.ToString(),
                Timeseries = tsr.Timeseries.Values,
                Labels = from k in tsr.Timeseries.Keys select new {label = k},
                TimeseriesInfo = tsr.Timeseries.Values.Select(ts => ts.Select(t => t.Value))
            }, new JsonConverter[] { new TimeseriesConverter(), new TimeseriesPeriodConverter() }));
        }
开发者ID:izevaka,项目名称:stacktagz,代码行数:14,代码来源:TimeseriesResultConverter.cs

示例9: WriteJson

        // Custom Biggylist serialization which simply writes each object, separated by newlines, to the output
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var list = value as IEnumerable;

              // Loop over all items in the list
              foreach (var item in list)
              {
            // Serialize the object to the writer
            serializer.Serialize(writer, item);

            // Separate with newline characters
            writer.WriteRaw("\r\n");
              }
        }
开发者ID:WilJoey,项目名称:biggy,代码行数:15,代码来源:BiggyListSerializer.cs

示例10: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var bulk = value as IBulkRequest;
			var settings = serializer?.GetConnectionSettings();
			var elasticsearchSerializer = settings?.Serializer;
			if (elasticsearchSerializer == null|| bulk?.Operations == null) return ;

			foreach(var op in bulk.Operations)
			{
				op.Index = op.Index ?? bulk.Index ?? op.ClrType;
				if (op.Index.EqualsMarker(bulk.Index)) op.Index = null;
				op.Type = op.Type ?? bulk.Type ?? op.ClrType;
				if (op.Type.EqualsMarker(bulk.Type)) op.Type = null;
				op.Id = op.GetIdForOperation(settings.Inferrer);

				var opJson = elasticsearchSerializer.SerializeToString(op, SerializationFormatting.None);
				writer.WriteRaw($"{{\"{op.Operation}\":" + opJson + "}\n");
				var body = op.GetBody();
				if (body == null) continue;
				var bodyJson = elasticsearchSerializer.SerializeToString(body, SerializationFormatting.None);
				writer.WriteRaw(bodyJson + "\n");
			}
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:23,代码来源:BulkRequestJsonConverter.cs

示例11: WriteJson

        /// <summary>
        /// Data should be written as an array of arrays, according to Flot specification. 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="value">Should be a dictionary.</param>
        /// <param name="serializer"></param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            // I'm not sure if this is needed.
            if (!(value is IDictionary)) throw new Exception("Value is not a dictionary.");

            foreach (dynamic teste in (IEnumerable)value)
            {
                writer.WriteStartArray();
                serializer.Serialize(writer, teste.Key);
                serializer.Serialize(writer, teste.Value);
                writer.WriteEndArray();
                writer.WriteRaw(", ");
            }
        }
开发者ID:renilsonmeneguci,项目名称:Flot.Mvc,代码行数:20,代码来源:FlotDataDictionarySerializer.cs

示例12: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
             HasChildFilter term = (HasChildFilter)value;
             if (term != null)
             {

                 writer.WriteStartObject();
                 writer.WritePropertyName("has_child");
                 writer.WriteStartObject();

                 if (term.Query != null)
                 {
                     writer.WritePropertyName("query");
                     serializer.Serialize(writer, term.Query);
                     writer.WriteRaw(",\"type\": \"" + term.Type+"\"");
                     if(term.Scope!=null)
                     {
                         writer.WriteRaw(",\"_scope\": \"" + term.Scope + "\"");    
                     }
                 }
                 writer.WriteEndObject();
                 writer.WriteEndObject();
             }
        }
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:24,代码来源:HasChildFilterConvert.cs

示例13: WriteJson

 public override void WriteJson(JsonWriter writer, object value)
 {
     if (value is DateTime)
     {
         writer.WriteValue(JsonConvert.ConvertDateTimeToJavaScriptTicks((DateTime)value));
     }
     else if (value is DateTime? && ((DateTime?)value).HasValue)
     {
         writer.WriteValue(JsonConvert.ConvertDateTimeToJavaScriptTicks(((DateTime?)value).Value));
     }
     else
     {
         writer.WriteRaw("null");
     }
 }
开发者ID:suwatch,项目名称:svcodecampweb,代码行数:15,代码来源:LongDateTimeConverter.cs

示例14: WriteJson

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

            writer.WriteStartArray();
            byte[] arbitraryData = (byte[]) value;
            writer.WriteRaw(string.Join(",", arbitraryData));
            writer.WriteEndArray();
        }
开发者ID:no1dead,项目名称:HaloOnlineServer,代码行数:16,代码来源:AbstractDataConverter.cs

示例15: WriteTo

        /// <summary>
        /// Writes this token to a <see cref="JsonWriter"/>.
        /// </summary>
        /// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
        /// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
        public override void WriteTo(JsonWriter writer, params JsonConverter[] converters) {
            writer.WriteStartObject();
            if (this.WithComment) {
                var lPath = writer.Path;
                var lState = writer.WriteState;
                StringBuilder lComments = new StringBuilder();
                int lLevel = (lPath.Split('.').Length + 1) * 2;
                if (lPath == "") lLevel = 2;
                writer.WriteWhitespace("\r\n");
                for (int lCount = 0; lCount < mComment.Count; lCount++) {
                    if (lLevel > 0) writer.WriteWhitespace(new string(' ', lLevel));
                    writer.WriteRaw("//" + mComment[lCount]);
                    if (lCount + 1 < mComment.Count) writer.WriteWhitespace("\r\n");
                }
            }
            var _properties = base.Properties();
            foreach (var lProperty in _properties) {
                lProperty.WriteTo(writer, converters);
            }
            writer.WriteEndObject();


            //base.WriteTo(writer, converters);
        }
开发者ID:ivan73,项目名称:json,代码行数:29,代码来源:JCommentOverrides.cs


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