當前位置: 首頁>>代碼示例>>C#>>正文


C# JsonWriter.WritePropertyName方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.JsonWriter.WritePropertyName方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonWriter.WritePropertyName方法的具體用法?C# JsonWriter.WritePropertyName怎麽用?C# JsonWriter.WritePropertyName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.JsonWriter的用法示例。


在下文中一共展示了JsonWriter.WritePropertyName方法的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: Write

        public void Write(JsonWriter writer)
        {
            Validate();

            writer.WriteStartObject();

            writer.WritePropertyName("key");
            writer.WriteValue(Key);

            if (!string.IsNullOrEmpty(ChangeMessage))
            {
                writer.WritePropertyName("changeMessage");
                writer.WriteValue(ChangeMessage);
            }

            if (!string.IsNullOrEmpty(Label))
            {
                writer.WritePropertyName("label");
                writer.WriteValue(Label);
            }

            if (TextAlignment != FieldTextAlignment.Unspecified)
            {
                writer.WritePropertyName("textAlignment");
                writer.WriteValue(TextAlignment);
            }

            WriteKeys(writer);

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

            writer.WriteEndObject();
        }
開發者ID:Harleyd210,項目名稱:dotnet-passbook,代碼行數:34,代碼來源:Field.cs

示例3: WriteJson

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

            //{
            writer.WriteStartObject();

            // "DatasetInterval" : "1"
            writer.WritePropertyName("DatasetInterval");
            writer.WriteValue(heartActivitiesIntraday.DatasetInterval);

            // "DatasetType" : "SecondsHeartrate"
            writer.WritePropertyName("DatasetType");
            writer.WriteValue(heartActivitiesIntraday.DatasetType);

            writer.WritePropertyName("Dataset");
            writer.WriteStartArray();
            foreach (var datasetInverval in heartActivitiesIntraday.Dataset)
            {
                // "Time" : "2008-09-22T14:01:54.9571247Z"
                writer.WritePropertyName("Time");
                writer.WriteValue(datasetInverval.Time.ToString("o"));

                // "Value": 1
                writer.WritePropertyName("Value");
                writer.WriteValue(datasetInverval.Value);

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

        }
開發者ID:lobrien,項目名稱:Fitbit.NET,代碼行數:34,代碼來源:HeartActivitiesIntraday.cs

示例4: WriteJson

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

            list.Links.Add(new Link
            {
                Rel = "self",
                Href = list.Href
            });

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

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (HalResource halResource in (IEnumerable)value)
            {
                serializer.Serialize(writer, halResource);
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
            writer.WriteEndObject();
        }
開發者ID:mabster,項目名稱:WebApi.Hal,代碼行數:26,代碼來源:ResourceListConverter.cs

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

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

示例7: Write

        public void Write(JsonWriter writer)
        {
            Validate();

            writer.WriteStartObject();

            writer.WritePropertyName("proximityUUID");
            writer.WriteValue(ProximityUUID);

            if (!string.IsNullOrEmpty(RelevantText))
            {
                writer.WritePropertyName("relevantText");
                writer.WriteValue(RelevantText);
            }

            if (Minor.HasValue)
            {
                writer.WritePropertyName("minor");
                writer.WriteValue(Minor);
            }

            if (Major.HasValue)
            {
                writer.WritePropertyName("major");
                writer.WriteValue(Major);
            }

            writer.WriteEndObject();
        }
開發者ID:joe-keane,項目名稱:dotnet-passbook,代碼行數:29,代碼來源:RelevantBeacon.cs

示例8: WriteJson

        public override JsonWriter WriteJson(JsonWriter writer)
        {
            if(Filters.Count > 0)
            {
                writer.WritePropertyName("inputs");
                writer.WriteStartObject();

                writer.WritePropertyName("bucket");
                writer.WriteValue(_bucket);

                writer.WritePropertyName("key_filters");
                writer.WriteStartArray();

                Filters.ForEach(f => writer.WriteRawValue(f.ToJsonString()));

                writer.WriteEndArray();
                writer.WriteEndObject();
            }
            else
            {
                writer.WritePropertyName("inputs");
                writer.WriteValue(_bucket);
            }

            return writer;
        }
開發者ID:taliesins,項目名稱:CorrugatedIron,代碼行數:26,代碼來源:RiakBucketInput.cs

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

示例10: WriteJson

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

				if (!string.IsNullOrEmpty(term.NormsField))
				{
					writer.WritePropertyName("norms_field");
					writer.WriteValue(term.NormsField);
				}

				if (term.Boost > 0)
				{
					writer.WritePropertyName("boost");
					writer.WriteValue(term.Boost);
				}

				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
開發者ID:starckgates,項目名稱:ElasticSearch.Net,代碼行數:25,代碼來源:MatchAllQueryConverter.cs

示例11: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			FieldQuery term = (FieldQuery)value;
			if (term != null)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("field");
				writer.WriteStartObject();
				writer.WritePropertyName(term.Field);
				writer.WriteValue(term.QueryString);
				
				if(!term.Boost.Equals(default(float)))
				{
					writer.WritePropertyName("boost");
					writer.WriteValue(term.Boost);	
				}

				if (term.EnablePositionIncrements != default(bool))
				{
					writer.WritePropertyName("enable_position_increments");
					writer.WriteValue(term.EnablePositionIncrements.ToString().ToLower());
				}

				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
開發者ID:starckgates,項目名稱:ElasticSearch.Net,代碼行數:27,代碼來源:FieldQueryConverter.cs

示例12: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            FeatureResult f = (FeatureResult)value;

            writer.WriteStartObject();

            if (f.Id != null){
                writer.WritePropertyName("id");
                writer.WriteValue(f.Id);
            }

            if (f.Properties != null) {
                writer.WritePropertyName("properties");
                serializer.Serialize(writer, f.Properties);
            }

            writer.WritePropertyName("type");
            serializer.Serialize(writer, (f.Type));

            if (f.Geometry != null) {
                writer.WritePropertyName("geometry");
                serializer.Serialize(writer, f.Geometry);
            }

            writer.WriteEndObject();
        }
開發者ID:Terradue,項目名稱:DotNetOpenSearchGeoJson,代碼行數:26,代碼來源:FeatureResultJsonConverter.cs

示例13: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     // value should be an entity or a collection of entities.
     var singleEntity = !(value is IEnumerable);
     writer.WriteStartObject();
     writer.WritePropertyName("@odata.context");
     writer.WriteValue(GenerateContextUrlString(value, singleEntity));
     if (!singleEntity)
     {
         writer.WritePropertyName("value");
         writer.WriteStartArray();
     }
     if (singleEntity)
     {
         WriteEntity(writer, value);
     }
     else
     {
         foreach (var o in (IEnumerable)value)
         {
             writer.WriteStartObject();
             WriteEntity(writer, o);
             writer.WriteEndObject();
         }
     }
     if (!singleEntity)
     {
         writer.WriteEndArray();
     }
     writer.WriteEndObject();
 }
開發者ID:ZhaoYngTest01,項目名稱:WebApi,代碼行數:31,代碼來源:ODataJsonConverter.cs

示例14: WriteJson

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

            MerkleNode mn = value as MerkleNode;

            writer.WriteStartObject();

            writer.WritePropertyName("Data");
            serializer.Serialize(writer, mn.Data);

            writer.WritePropertyName("Hash");
            serializer.Serialize(writer, mn.Hash);

            writer.WritePropertyName("Links");
            serializer.Serialize(writer, mn.Links);

            writer.WritePropertyName("Name");
            serializer.Serialize(writer, mn.Name);

            writer.WritePropertyName("Size");
            serializer.Serialize(writer, mn.Size);

            writer.WriteEndObject();
        }
開發者ID:TrekDev,項目名稱:net-ipfs-api,代碼行數:29,代碼來源:MerkleNodeConverter.cs

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


注:本文中的Newtonsoft.Json.JsonWriter.WritePropertyName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。