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


C# JsonWriter.WriteStartObject方法代码示例

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


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

示例1: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var representation = value as Representation;
            if (representation != null)
                representation.RepopulateHyperMedia();

            var list = (IRepresentationList)value;

            writer.WriteStartObject();
            writer.WritePropertyName("_links");
            serializer.Serialize(writer, list.Links);

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (Representation halResource in list)
            {
                serializer.Serialize(writer, halResource);
            }

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

            var listType = list.GetType();
            var propertyInfos = typeof(RepresentationList<>).GetProperties().Select(p => p.Name);
            foreach (var property in listType.GetProperties().Where(p => !propertyInfos.Contains(p.Name)))
            {
                writer.WritePropertyName(property.Name.ToLower());
                serializer.Serialize(writer, property.GetValue(value, null));
            }

            writer.WriteEndObject();
        }
开发者ID:JoryUK,项目名称:WebApi.Hal,代码行数:34,代码来源:ResourceListConverter.cs

示例2: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var f = value as IGeoBoundingBoxFilter;
			if (f == null || (f.IsConditionless && !f.IsVerbatim)) return;
			
			var contract = serializer.ContractResolver as SettingsContractResolver;
			if (contract == null)
				return;
			
			var field = contract.Infer.PropertyPath(f.Field);
			if (field.IsNullOrEmpty())
				return;

			writer.WriteStartObject();
			{
				writer.WritePropertyName(field);
				writer.WriteStartObject();
				{
					WriteProperty(writer, f, "top_left", f.TopLeft);
					WriteProperty(writer, f, "bottom_right", f.BottomRight);
				}
				writer.WriteEndObject();
				SerializeProperty(writer, serializer, f, "type", f.GeoExecution);
				
				WriteProperty(writer, f, "_cache", f.Cache);
				WriteProperty(writer, f, "_cache_key", f.CacheKey);
				WriteProperty(writer, f, "_name", f.FilterName);
			}
			writer.WriteEndObject();
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:30,代码来源:GeoBoundingFilterConverter.cs

示例3: WriteJson

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

				writer.WritePropertyName("type");
				writer.WriteValue(term.Type);

				writer.WritePropertyName("score");
				writer.WriteValue( term.Score);

				writer.WritePropertyName("factor");
				writer.WriteValue(term.Factor);

				writer.WritePropertyName("incremental_factor");
				writer.WriteValue(term.IncrementalFactor);

				writer.WritePropertyName("query");
				serializer.Serialize(writer, term.Query);

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

示例4: 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

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var request = value as UpdateListItemsRequest;
            if (request == null)
            {
                writer.WriteNull();
                return;
            }
            /*
             "additems" : ["3","4","5"],
            "adduniqueitems" : ["1","6"],
            "removeitems": ["2","5"]
             */
            writer.WriteStartObject();
            writer.WritePropertyName(request.Property );
            writer.WriteStartObject();
            if (request.ItemsToAdd.Count > 0)
            {
                if (request.AddUniquely == true)
                    writer.WriteArray("adduniqueitems", request.ItemsToAdd);
                else
                    writer.WriteArray("additems", request.ItemsToAdd);
            }
            if (request.ItemsToRemove.Count > 0)
                writer.WriteArray("removeitems", request.ItemsToRemove);

            writer.WriteEndObject();
            writer.WriteEndObject();
        }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:29,代码来源:UpdateListItemsRequestConverter.cs

示例6: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			DisjunctionMaxQuery term = (DisjunctionMaxQuery)value;
			if (term != null)
			{
				if (term.Queries == null || term.Queries.Count < 0)
				{
					throw new ArgumentException();
				}

				writer.WriteStartObject();
				writer.WritePropertyName("dis_max");
				writer.WriteStartObject();
				writer.WritePropertyName("tie_breaker");
				writer.WriteValue(term.TieBreaker);
				writer.WritePropertyName("boost");
				writer.WriteValue(term.Boost);
				writer.WritePropertyName("queries");
				writer.WriteStartArray();
				foreach (var query in term.Queries)
				{
					serializer.Serialize(writer, query);
				}
				writer.WriteEndArray();
				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:28,代码来源:DisjunctionMaxQueryConverter.cs

示例7: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			TermQuery term = (TermQuery)value;
            if (term != null)
            {
                /* Writes the following json
                 *  {
                 *      "term":
                 *      {
                 *          "term.Field": 
                 *          {
                 *              "term": "term.Value",
                 *              "boost": term.Boost
                 *          }
                 *      }
                 *  }
                 */

                writer.WriteStartObject();
                writer.WritePropertyName("term");
                writer.WriteStartObject();
                writer.WritePropertyName(term.Field);
                writer.WriteStartObject();
                writer.WritePropertyName("term");
                writer.WriteValue(term.Value);
                writer.WritePropertyName("boost");
                writer.WriteValue(term.Boost);
                writer.WriteEndObject();
                writer.WriteEndObject();
                writer.WriteEndObject();
            }
            //writer.WriteRawValue(string.Format("{{term: {{ \"{0}\" : {{ \"term\" : \"{1}\", \"boost\":{2} }}}} }}", term.Field, term.Value, term.Boost));
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:33,代码来源:TermQueryConvert.cs

示例8: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");
            if (value == null)
                throw new ArgumentNullException("value");
            if (serializer == null)
                throw new ArgumentNullException("serializer");
            if (!(value is IFeature))
            {
                string s = String.Format("IFeature expected but was {0}", value.GetType().Name);
                throw new ArgumentException(s);
            }

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("Topology");

            writer.WritePropertyName("objects");
            writer.WriteStartObject();
            writer.WritePropertyName("data");
            IEnumerable<Coordinate[]> arcs = WriteFeature(writer, serializer, (IFeature)value);
            writer.WriteEndObject();

            WriteArcs(writer, serializer, arcs);
            writer.WriteEndObject();
        }
开发者ID:Walt-D-Cat,项目名称:NetTopologySuite,代码行数:27,代码来源:TopoFeatureConverter.cs

示例9: WriteJson

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

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

                if (!string.IsNullOrEmpty(term.Distance))
                {
                    writer.WritePropertyName("distance");
                    writer.WriteValue(term.Distance);

                    if (!string.IsNullOrEmpty(term.DistanceType))
                    {
                        writer.WritePropertyName("distance_type");
                        writer.WriteValue(term.DistanceType);
                    }
                    if (!string.IsNullOrEmpty(term.Field))
                    {
                        writer.WritePropertyName(term.Field);
                        writer.WriteValue(term.Location);
                    }

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

示例10: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value.IsNot<NestedFilter>())
     {
         writer.WriteNull();
         return;
     }
     var filter = (NestedFilter)value;
     writer.WriteStartObject();
     writer.WritePropertyName("nested");
     writer.WriteStartObject();
     if (filter.Path.IsNotNull())
     {
         writer.WritePropertyName("path");
         writer.WriteValue(filter.Path);
     }
     writer.WritePropertyName("filter");
     serializer.Serialize(writer, filter.Filter);
     if (filter.Join.IsNotNull())
     {
         writer.WritePropertyName("join");
         writer.WriteValue(filter.Join);
     }
     writer.WriteEndObject();
     writer.WriteEndObject();
 }
开发者ID:OpenDeepmind,项目名称:Nested2Find,代码行数:26,代码来源:NestedFilterConverter.cs

示例11: WriteJson

        public override void WriteJson(JsonWriter __writer, object __value, JsonSerializer __serializer)
        {
            var __对象 = (M接收事件)__value;
            __writer.WriteStartObject();
            __writer.WritePropertyName("对象名称");
            __writer.WriteValue(__对象.对象名称);
            __writer.WritePropertyName("事件名称");
            __writer.WriteValue(__对象.事件名称);
            __writer.WritePropertyName("实参列表");
            __writer.WriteStartArray();
            if (__对象.实参列表 != null)
            {
                foreach (var __kv in __对象.实参列表)
                {
                    __writer.WriteStartObject();
                    __writer.WritePropertyName("名称");
                    __writer.WriteValue(__kv.名称);
                    __writer.WritePropertyName("值");

                    if (__kv.值.TrimStart().StartsWith("{") || __kv.值.TrimStart().StartsWith("["))
                    {
                        __writer.WriteRawValue(__kv.值);
                    }
                    else
                    {
                        __writer.WriteValue(__kv.值);
                    }
                    __writer.WriteEndObject();
                }
            }
            __writer.WriteEndArray();
            __writer.WriteEndObject();
        }
开发者ID:xiaomiwk,项目名称:K_tongyongfangwen,代码行数:33,代码来源:M接收事件Converter.cs

示例12: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var facetRequest = (NestedDateHistogramFacetRequest)value;
     writer.WriteStartObject();
     writer.WritePropertyName("date_histogram");
     writer.WriteStartObject();
     if (facetRequest.Field.IsNotNullOrEmpty())
     {
         writer.WritePropertyName("field");
         writer.WriteValue(facetRequest.Field);
     }
     if (facetRequest.Interval.IsNotNull())
     {
         writer.WritePropertyName("interval");
         writer.WriteValue(facetRequest.Interval.ToString().ToLowerInvariant());
     }
     if (facetRequest.PreTimeZone.IsNotNull())
     {
         writer.WritePropertyName("pre_zone");
         writer.WriteValue(facetRequest.PreTimeZone.BaseUtcOffset.ToString(@"hh\:mm"));
     }
     writer.WriteEndObject();
     if (facetRequest.Nested.IsNotNullOrEmpty())
     {
         writer.WritePropertyName("nested");
         writer.WriteValue(facetRequest.Nested);
     }
     if (facetRequest.FacetFilter.IsNotNull())
     {
         writer.WritePropertyName("facet_filter");
         serializer.Serialize(writer, facetRequest.FacetFilter);
     }
     writer.WriteEndObject();
 }
开发者ID:OpenDeepmind,项目名称:Nested2Find,代码行数:34,代码来源:NestedDateHistogramFacetRequestConverter.cs

示例13: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            PacketEffect effect = (PacketEffect)value;
                PacketEffectAttribute effectAttribute = effect.GetType().GetCustomAttribute<PacketEffectAttribute>();
                if (effectAttribute == null)
                    throw new NotSupportedException("All PacketEffect classes must have a PacketEffectAttribute !");

                writer.WriteStartObject();
                writer.WritePropertyName(effectAttribute.Name);
                writer.WriteStartObject();
                foreach (PropertyInfo info in value.GetType().GetProperties())
                {
                    string propertyName;
                    JsonPropertyAttribute propertyAttribute = info.GetCustomAttribute<JsonPropertyAttribute>();
                    if (propertyAttribute != null)
                        propertyName = propertyAttribute.PropertyName;
                    else
                        propertyName = info.Name;
                    writer.WritePropertyName(propertyName);

                    JsonConverterAttribute conversionAttribute = info.GetCustomAttribute<JsonConverterAttribute>();
                    if (conversionAttribute != null)
                        writer.WriteRawValue(JsonConvert.SerializeObject(info.GetValue(value), Formatting.None, (JsonConverter)Activator.CreateInstance(conversionAttribute.ConverterType)));
                    else
                        writer.WriteRawValue(JsonConvert.SerializeObject(info.GetValue(value)));
                }
                writer.WriteEndObject();
                writer.WriteEndObject();
        }
开发者ID:MarechalBanane,项目名称:RelentlessZero,代码行数:29,代码来源:Packets.cs

示例14: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var poi = (PoiData)value;

            writer.WriteStartObject();

            if (!string.IsNullOrEmpty(poi.Id))
            {
                writer.WritePropertyName(poi.Id);
                writer.WriteStartObject();
            }

            WriteNewObject(writer, poi, serializer, "fw_core", poi.Core);
            WriteNewObject(writer, poi, serializer, "fw_time", poi.Time);
            WriteNewObject(writer, poi, serializer, "fw_xml3d", poi.Xml3ds);
            WriteNewObject(writer, poi, serializer, "fw_contact", poi.Contacts);
            WriteNewObject(writer, poi, serializer, "fw_media", poi.Media);
            WriteNewObject(writer, poi, serializer, "fw_relationships", poi.Relationships);
            WriteNewObject(writer, poi, serializer, "fw_marker", poi.Markers);

            if (!string.IsNullOrEmpty(poi.Id))
            {
                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
开发者ID:TuerCo,项目名称:PoiProvider,代码行数:27,代码来源:PoiDataConverter.cs

示例15: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     TermsFacet term = (TermsFacet)value;
     if (term != null)
     {
         if (term.facetItems != null)
         {
             writer.WriteStartObject();
             foreach (TermsFacet.TermsFacetItem termsFacetItem in term.facetItems)
             {
                 writer.WritePropertyName(termsFacetItem.FacetName);
                 writer.WriteStartObject();
                 //1
                 writer.WritePropertyName("terms");
                 writer.WriteStartObject();
                 writer.WritePropertyName("field");
                 writer.WriteValue(termsFacetItem.Field);
                 writer.WritePropertyName("size");
                 writer.WriteValue(termsFacetItem.Size);
                 writer.WriteEndObject();
                 //1
                 writer.WriteEndObject();
             }
             writer.WriteEndObject();
         }
     }
 }
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:27,代码来源:TermsFacetConverterer.cs


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