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


C# JsonWriter.WriteValue方法代码示例

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


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

示例1: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var sort = value as SortGeoDistanceDescriptor;
     if (sort != null)
     {
         writer.WriteStartObject();
         if (sort._Missing != null)
         {
             writer.WritePropertyName("missing");
             writer.WriteValue(sort._Missing);
         }
         if (sort._Order != null)
         {
             writer.WritePropertyName("order");
             writer.WriteValue(sort._Order);
         }
         if (sort._PinLocation != null)
         {
             writer.WritePropertyName(sort._Field);
             writer.WriteValue(sort._PinLocation);
         }
         if (sort._GeoUnit.HasValue)
         {
             writer.WritePropertyName("unit");
             var v = Enum.GetName(typeof(GeoUnit), sort._GeoUnit.Value);
             writer.WriteValue(v);
         }
         writer.WriteEndObject();
     }
     else
         writer.WriteNull();
 }
开发者ID:romankor,项目名称:NEST,代码行数:32,代码来源:SortGeoDistanceDescriptorConverter.cs

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

示例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)
		{
			var t = value as ITermsQuery;
			if (t == null) return;

			var settings = serializer.GetConnectionSettings();
			var field = settings.Inferrer.Field(t.Field);

			writer.WriteStartObject();
			{
				if (t.Terms.HasAny())
				{
					writer.WritePropertyName(field);
					serializer.Serialize(writer, t.Terms);
				}
				else if (t.TermsLookup != null)
				{
					writer.WritePropertyName(field);
					serializer.Serialize(writer, t.TermsLookup);
				}
				if (t.Boost.HasValue)
				{
					writer.WritePropertyName("boost");
					writer.WriteValue(t.Boost.Value);
				}
				if (!t.Name.IsNullOrEmpty())
				{
					writer.WritePropertyName("_name");
					writer.WriteValue(t.Name);
				}
			}
			writer.WriteEndObject();
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:33,代码来源:TermsQueryJsonConverter.cs

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

示例6: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            switch (serializer.TypeNameHandling)
            {
                case TypeNameHandling.All:
                    writer.WriteStartObject();
                    writer.WritePropertyName("$type", false);

                    switch (serializer.TypeNameAssemblyFormat)
                    {
                        case FormatterAssemblyStyle.Full:
                            writer.WriteValue(value.GetType().AssemblyQualifiedName);
                            break;
                        default:
                            writer.WriteValue(value.GetType().FullName);
                            break;
                    }

                    writer.WritePropertyName("$value", false);
                    writer.WriteValue(value);
                    writer.WriteEndObject();
                    break;
                default:
                    writer.WriteValue(value);
                    break;
            }
        }
开发者ID:Inverness,项目名称:Coroutines,代码行数:27,代码来源:PrimitiveJsonConverter.cs

示例7: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = (IList<Link>) value;
            writer.WriteStartObject();

            foreach (var link in links)
            {
                writer.WritePropertyName(link.Rel);
                writer.WriteStartObject();
                writer.WritePropertyName("href");
                writer.WriteValue(link.Href);

                if (link.IsTemplated)
                {
                    writer.WritePropertyName("isTemplated");
                    writer.WriteValue(true);
                }

                if (!string.IsNullOrWhiteSpace(link.Title))
                {
                    writer.WritePropertyName("title");
                    writer.WriteValue(link.Title);
                }
                

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

示例8: 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)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Enum e = (Enum)value;

            string enumName = e.ToString("G");

            if (char.IsNumber(enumName[0]) || enumName[0] == '-')
            {
                // enum value has no name so write number
                writer.WriteValue(value);
            }
            else
            {
                Type enumType = e.GetType();

                string finalName = EnumUtils.ToEnumName(enumType, enumName, CamelCaseText);

                writer.WriteValue(finalName);
            }
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:32,代码来源:StringEnumConverter.cs

示例9: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if (Guid.Empty.Equals(value))
				writer.WriteValue("");
			else
				writer.WriteValue(((Guid)value).ToString());
		}
开发者ID:w01f,项目名称:VolgaTeam.SalesLibrary,代码行数:7,代码来源:GuidConverter.cs

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

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

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

示例13: WriteJson

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

            Type objectType = objVal.GetType(),
                 enumType = GetActualEnumType(objectType);
            EnumInfo enumInfo = GetEnumInfo(enumType);
            ulong val = Convert.ToUInt64(objVal);

            if (!enumType.IsDefined(typeof(FlagsAttribute), false) || val == 0) {
                var valIndex = enumInfo.Values.IndexOf(val);
                writer.WriteValue(valIndex != -1 ? enumInfo.Names[valIndex] : objVal.ToString());
            }
            else {
                var sbVal = new StringBuilder();
                bool isFirstVal = true;

                for (int i = 0; i < enumInfo.Values.Count; i++) {
                    if (enumInfo.Values[i] != 0 && (val & enumInfo.Values[i]) == enumInfo.Values[i]) {
                        val -= enumInfo.Values[i];
                        if (!isFirstVal)
                            sbVal.Append(", ");
                        sbVal.Append(enumInfo.Names[i]);
                        isFirstVal = false;
                    }
                }

                writer.WriteValue(val == 0 ? sbVal.ToString() : objVal.ToString());
            }
        }
开发者ID:binki,项目名称:Alba.Framework,代码行数:33,代码来源:EnumFlagsConverter.cs

示例14: WriteJson

        /// <inheritdoc/>
        public override JsonWriter WriteJson(JsonWriter writer)
        {
            writer.WritePropertyName("inputs");
            writer.WriteStartObject();

            writer.WritePropertyName("module");
            writer.WriteValue(Module);

            writer.WritePropertyName("function");
            writer.WriteValue(Function);

            writer.WritePropertyName("arg");

            writer.WriteStartArray();

            foreach (string arg in Arg)
            {
                writer.WriteValue(arg);
            }

            writer.WriteEndArray();

            writer.WriteEndObject();

            return writer;
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:27,代码来源:RiakModuleFunctionArgInput.cs

示例15: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var model = value as LinkModel;
            if(model!=null)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("href");
                writer.WriteValue(model.Href);

                writer.WritePropertyName("rel");
                writer.WriteValue(model.Rel);

                if(!model.Method.Equals("GET",StringComparison.OrdinalIgnoreCase))
                {
                    writer.WritePropertyName("method");
                    writer.WriteValue(model.Method);
                }

                if(model.IsTemplated)
                {
                    writer.WritePropertyName("isTemplated");
                    writer.WriteValue(model.IsTemplated);
                }

                writer.WriteEndObject();
            }
        }
开发者ID:nywebman,项目名称:WebApiFoodDiary,代码行数:28,代码来源:LinkModelConverter.cs


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