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


C# JsonWriter.WriteStartArray方法代码示例

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


在下文中一共展示了JsonWriter.WriteStartArray方法的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 marker = value as Indices;
			if (marker == null)
			{
				writer.WriteNull();
				return;
			}
			marker.Match(
				all =>
				{
					writer.WriteStartArray();
					writer.WriteValue("_all");
					writer.WriteEndArray();
				},
				many =>
				{
					var settings = serializer.GetConnectionSettings();
					writer.WriteStartArray();
					foreach (var m in many.Indices.Cast<IUrlParameter>())
						writer.WriteValue(m.GetString(settings));
					writer.WriteEndArray();
				}
			);
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:25,代码来源:IndicesJsonConverter.cs

示例3: FormatJson

        public void FormatJson(ref JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("type");
            writer.WriteValue("table");

            writer.WritePropertyName("headers");
            writer.WriteStartArray();
            foreach(var header in this.headers.ToArray())
            {
                writer.WriteValue(header);
            }
            writer.WriteEndArray();

            writer.WritePropertyName("rows");
            writer.WriteStartArray();
            foreach (var row in this.rows.ToArray())
            {
                writer.WriteStartArray();

                foreach( var field in row)
                {
                    writer.WriteValue(field);
                }

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

            writer.WriteEndObject();
        }
开发者ID:BrixIT,项目名称:CRT-Client,代码行数:32,代码来源:Table.cs

示例4: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			BoolQuery term = (BoolQuery)value;
			if (term != null)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("bool");
				writer.WriteStartObject();
				bool pre = false;
				if(term.MustQueries!=null&&term.MustQueries.Count>0)
				{
					writer.WritePropertyName("must");
					writer.WriteStartArray();
					foreach (var VARIABLE in term.MustQueries)
					{
						serializer.Serialize(writer, VARIABLE);
					}
					writer.WriteEndArray();
				}
				if (term.MustNotQueries != null&&term.MustNotQueries.Count>0)
				{
					writer.WritePropertyName("must_not");
					writer.WriteStartArray();
					foreach (var VARIABLE in term.MustNotQueries)
					{
						serializer.Serialize(writer, VARIABLE);
					}
					writer.WriteEndArray();
				}
				if (term.ShouldQueries !=null&& term.ShouldQueries.Count > 0)
				{
					writer.WritePropertyName("should");
					writer.WriteStartArray();
					foreach (var shouldQuery in term.ShouldQueries)
					{
						serializer.Serialize(writer,shouldQuery);
					}
					writer.WriteEndArray();
				}
				if (Math.Abs(term.Boost - 1.0) > 0)
				{
					writer.WritePropertyName("boost");
					writer.WriteValue(term.Boost);
				}
				if (term.DisableCoord)
				{
					writer.WritePropertyName("disable_coord");
					writer.WriteValue(term.DisableCoord);
				}
				if (term.MinimumNumberShouldMatch != 1)
				{
					writer.WritePropertyName("minimum_number_should_match");
					writer.WriteValue(term.MinimumNumberShouldMatch);
				}
				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:58,代码来源:BoolQueryConverter.cs

示例5: WriteJson

        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var polygons = (List<Polygon>)value;
            
            writer.WriteStartArray();
            
            if (polygons != null && polygons.Count > 0)
            {
                for (int i = 0; i < polygons.Count; i++)
                {
                    var polygon = polygons[i];
                    
                    // start of polygon
                    writer.WriteStartArray();

                    for (int j = 0; j < polygon.Coordinates.Count; j++)
                    {
                        var lineString = polygon.Coordinates[j];
                        var coordinateElements = lineString.Coordinates.OfType<GeographicPosition>();
                        if (coordinateElements.Any())
                        {
                            // start linear rings of polygon
                            writer.WriteStartArray();

                            foreach (var position in coordinateElements)
                            {
                                var coordinates = position;

                                writer.WriteStartArray();

                                writer.WriteValue(coordinates.Longitude);
                                writer.WriteValue(coordinates.Latitude);

                                if (coordinates.Altitude.HasValue)
                                {
                                    writer.WriteValue(coordinates.Altitude.Value);
                                }

                                writer.WriteEndArray();
                            }

                            writer.WriteEndArray();
                        }
                    }

                    writer.WriteEndArray();
                }

                writer.WriteEndArray();
            }
        }
开发者ID:tobiashoeft,项目名称:GeoJSON.Net,代码行数:57,代码来源:MultiPolygonConverter.cs

示例6: WriteJson

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

            writer.WritePropertyName("entityColumn");
            writer.WriteValue(rt.EntityColumn?.Name);

            writer.WritePropertyName("columns");
            serializer.Serialize(writer, rt.Columns.Select(c => c.Column.Token.FullKey()).ToList());

            writer.WritePropertyName("pagination");
            serializer.Serialize(writer, new PaginationTS(rt.Pagination));

            writer.WritePropertyName("totalElements");
            writer.WriteValue(rt.TotalElements);


            writer.WritePropertyName("rows");
            writer.WriteStartArray();
            foreach (var row in rt.Rows)
            {
                writer.WriteStartObject();
                if (rt.EntityColumn != null)
                {
                    writer.WritePropertyName("entity");
                    serializer.Serialize(writer, row.Entity);
                }

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                foreach (var column in rt.Columns)
                {
                    using (JsonSerializerExtensions.SetCurrentPropertyRoute(column.Column.Token.GetPropertyRoute()))
                    {
                        serializer.Serialize(writer, row[column]);
                    }
                }
                writer.WriteEndArray();


                writer.WriteEndObject();

            }
            writer.WriteEndArray();


            writer.WriteEndObject();
        }
开发者ID:signumsoftware,项目名称:framework,代码行数:50,代码来源:ResultTableConverter.cs

示例7: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var extent = (Extent)value;
     writer.WriteStartArray();
     writer.WriteStartArray();
     writer.WriteValue(extent.X1);
     writer.WriteValue(extent.Y1);
     writer.WriteEndArray();
     writer.WriteStartArray();
     writer.WriteValue(extent.X2);
     writer.WriteValue(extent.Y2);
     writer.WriteEndArray();
     writer.WriteEndArray();
 }
开发者ID:jcarrascal,项目名称:GisGlue,代码行数:14,代码来源:ExtentConverter.cs

示例8: WriteJson

        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var polygons = value as List<Polygon>;

            if (polygons != null)
            {
                writer.WriteStartArray();
                foreach (var polygon in polygons)
                {
                    // start of polygon
                    writer.WriteStartArray();

                    foreach (var lineString in polygon.Coordinates ?? new List<LineString>())
                    {
                        var coordinateElements = (lineString.Coordinates ?? new List<IPosition>())
                            .OfType<GeographicPosition>()
                            .ToList();

                        if (coordinateElements.Count == 0)
                            continue;

                        // start linear rings of polygon
                        writer.WriteStartArray();

                        foreach (var position in coordinateElements)
                        {
                            var coordinates = position;

                            writer.WriteStartArray();

                            writer.WriteValue(coordinates.Longitude);
                            writer.WriteValue(coordinates.Latitude);

                            if (coordinates.Altitude.HasValue)
                            {
                                writer.WriteValue(coordinates.Altitude.Value);
                            }

                            writer.WriteEndArray();
                        }

                        writer.WriteEndArray();
                    }

                    writer.WriteEndArray();
                }

                writer.WriteEndArray();
            }
        }
开发者ID:GeoJSON-Net,项目名称:GeoJSON.Net,代码行数:56,代码来源:MultiPolygonConverter.cs

示例9: WriteJson

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

            writer.WriteStartObject();

            foreach (var key in collection.AllKeys)
            {
                writer.WritePropertyName(key);

                var values = collection.GetValues(key);
                if (values == null)
                {
                    writer.WriteNull();
                    continue;
                }
                if (values.Length == 1)
                {
                    writer.WriteValue(values[0]);
                }
                else
                {
                    writer.WriteStartArray();

                    foreach (var item in values)
                    {
                        writer.WriteValue(item);
                    }

                    writer.WriteEndArray();
                }

            }
            writer.WriteEndObject();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:35,代码来源:NaveValueCollectionJsonConverterOnlyForConfigFormatters.cs

示例10: WriteJson

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

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

            writer.WriteStartArray();
            foreach(var kv in ts) {
                writer.WriteStartArray();
                writer.WriteValue(kv.Key.ToString("yyyy-MM-dd"));
                writer.WriteValue(kv.Value.Count);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
        }
开发者ID:izevaka,项目名称:stacktagz,代码行数:16,代码来源:TimeseriesConverter.cs

示例11: WriteJson

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

            writer.WriteStartArray();

            if (list == null || list.Count == 0)
            {
                foreach (var item in list)
                {
                    writer.WriteStartObject();
                    if (value != null)
                    {
                        var type = value.GetType();
                        var name = type.Name;
                        var attribute = type.GetCustomAttributes(typeof(JsonWrapPropertyAttribute), true).FirstOrDefault() as JsonWrapPropertyAttribute;
                        if (attribute != null)
                        {
                            name = attribute.WrapName;
                        }

                        writer.WritePropertyName(name);
                        serializer.Serialize(writer, value);

                    }
                    writer.WriteEndObject();
                }
            }
            writer.WriteEndArray();
        }
开发者ID:vshlos,项目名称:elasticsearch-sharp,代码行数:30,代码来源:ListObjectWrapConverter.cs

示例12: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            DataTable table = (DataTable)value;
            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            writer.WriteStartArray();

            foreach (DataRow row in table.Rows)
            {
                writer.WriteStartObject();
                foreach (DataColumn column in row.Table.Columns)
                {
                    object columnValue = row[column];

                    if (serializer.NullValueHandling == NullValueHandling.Ignore && (columnValue == null || columnValue == DBNull.Value))
                        continue;

                    writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(column.ColumnName) : column.ColumnName);
                    serializer.Serialize(writer, columnValue);
                }
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:31,代码来源:DataTableConverter.cs

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

示例14: WriteJson

        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var coordinateElements = value as List<LineString>;
            if (coordinateElements != null && coordinateElements.Count > 0)
            {
                if (coordinateElements[0].Coordinates[0] != null)
                {
                    writer.WriteStartArray();

                    foreach (var subPolygon in coordinateElements)
                    {
                        LineStringConverter.WriteJson(writer, subPolygon.Coordinates, serializer);
                    }

                    writer.WriteEndArray();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                serializer.Serialize(writer, value);
            }
        }
开发者ID:llambanna,项目名称:GeoJSON.Net,代码行数:32,代码来源:PolygonConverter.cs

示例15: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                var notifications = (ClientNotifications)value;
                writer.WriteStartArray();

                foreach (var p in notifications)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("id");
                    writer.WriteValue(p.Id.ToString("N"));
                    writer.WritePropertyName("message");
                    writer.WriteValue(p.Message);
                    writer.WritePropertyName("title");
                    writer.WriteValue(p.Title);
                    writer.WritePropertyName("type");
                    writer.WriteValue(p.Type.ToString().ToLower());
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }

        }
开发者ID:RebelCMS,项目名称:rebelcmsxu5,代码行数:28,代码来源:ClientNotificationsJsonConverter.cs


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