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


C# Json.JsonWriter类代码示例

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


JsonWriter类属于Newtonsoft.Json命名空间,在下文中一共展示了JsonWriter类的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("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

示例3: WriteJson

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

            writer.WriteStartObject();

            var groupedByRel = relations.Links
                .GroupBy(_ => _.Rel)
                .ToDictionary(_ => _.Key, _ => _.ToArray());

            var allRelsExceptWellKnown = groupedByRel.Keys
                .Where(key => key != Link.CuriesRel && key != Link.SelfRel).ToList();

            // Not strictly required, but we will write the nodes in a nice order.
            if (groupedByRel.ContainsKey(Link.SelfRel))
            {
                WriteLinks(writer, serializer, Link.SelfRel, links: groupedByRel[Link.SelfRel]);
            }

            if (groupedByRel.ContainsKey(Link.CuriesRel))
            {
                WriteLinks(writer, serializer, Link.CuriesRel, links: groupedByRel[Link.CuriesRel]);
            }

            foreach (var rel in allRelsExceptWellKnown)
            {
                WriteLinks(writer, serializer, rel, links: groupedByRel[rel]);
            }

            writer.WriteEndObject();
        }        
开发者ID:olohmann,项目名称:Lohmann.HALight,代码行数:31,代码来源:RelationsConverter.cs

示例4: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                var id = (HiveId)value;
                
                writer.WriteStartObject();
                writer.WritePropertyName("htmlId");
                writer.WriteValue(id.GetHtmlId());

                writer.WritePropertyName("rawValue");
                writer.WriteValue(id.ToString());

                writer.WritePropertyName("value");
                writer.WriteValue(id.Value.Value == null ? "" : id.Value.Value.ToString());

                writer.WritePropertyName("valueType");
                writer.WriteValue(id.Value.Type);

                writer.WritePropertyName("provider");
                writer.WriteValue(id.ProviderId.IsNullOrWhiteSpace() ? "" : id.ProviderId);

                writer.WritePropertyName("scheme");
                writer.WriteValue(id.ProviderGroupRoot == null ? "" : id.ProviderGroupRoot.ToString());

                writer.WriteEndObject();                
            }

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

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var mode = (GameMode)value;
            string result;
            switch (mode)
            {
                case GameMode.Classic:
                    result = "CLASSIC";
                    break;
                case GameMode.Aram:
                    result = "ARAM";
                    break;
                case GameMode.Dominion:
                    result = "ODIN";
                    break;
                case GameMode.FirstBlood:
                    result = "FIRSTBLOOD";
                    break;
                case GameMode.OneForAll:
                    result = "ONEFORALL";
                    break;
                case GameMode.Tutorial:
                    result = "TUTORIAL";
                    break;

                //Fix for rengar
                case GameMode.Any:
                    result = "any";
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            serializer.Serialize(writer, result);
        }
开发者ID:Zyano,项目名称:RiotSharp,代码行数:35,代码来源:GameModeConverter.cs

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

示例7: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var push = value as PushNotification;
            if (push == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            // Write push type
            if (string.IsNullOrWhiteSpace(push.Query) == false)
                writer.WriteProperty("query", push.Query);
            else if( push.Channels.Count() > 0 )
                writer.WriteArray("channels", push.Channels);
            else if( push.DeviceIds.Count() > 0 )
                writer.WriteArray("deviceids", push.DeviceIds);
            else
                writer.WriteProperty("broadcast", true);
            // Write data
            WriteData(writer, push);
            // Write platform options
            WritePlatformOptions(writer, push.PlatformOptions);
            writer.EndObject();

        }
开发者ID:neilunadkat,项目名称:appacitive-dotnet-sdk,代码行数:26,代码来源:PushNotificationConverter.cs

示例8: WriteTo

        public static void WriteTo(Bundle bundle, JsonWriter writer, bool summary = false)
        {
            if (bundle == null) throw new ArgumentException("Bundle cannot be null");

            JObject result = new JObject();

            result.Add(new JProperty(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME, "Bundle"));

            if (!String.IsNullOrWhiteSpace(bundle.Title))
                result.Add(new JProperty(BundleXmlParser.XATOM_TITLE, bundle.Title));
            if (SerializationUtil.UriHasValue(bundle.Id)) result.Add(new JProperty(BundleXmlParser.XATOM_ID, bundle.Id));
            if (bundle.LastUpdated != null) 
                result.Add(new JProperty(BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));

            if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
                result.Add(jsonCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
            if (bundle.TotalResults != null) result.Add(new JProperty(BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults.ToString()));
          
            if (bundle.Links.Count > 0)
                result.Add(new JProperty(BundleXmlParser.XATOM_LINK, jsonCreateLinkArray(bundle.Links)));
            if (bundle.Tags != null && bundle.Tags.Count() > 0)
                result.Add( TagListSerializer.CreateTagCategoryPropertyJson(bundle.Tags));

            var entryArray = new JArray();

            foreach (var entry in bundle.Entries)
                entryArray.Add(createEntry(entry,summary));

            result.Add(new JProperty(BundleXmlParser.XATOM_ENTRY, entryArray));

            result.WriteTo(writer);
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:32,代码来源:BundleJsonSerializer.cs

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

示例10: GetJson

        /// <summary>
        /// Gets the remote interface values from the given <see cref="XElement"/> as a <see cref="JObject"/>.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="element"></param>
        public static void GetJson(JsonWriter writer, XElement element)
        {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(element != null);

            serializer.Serialize(writer, element);
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:12,代码来源:RemoteHelper.cs

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

示例12: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var s = new StringWriter();
     var w = new JsonTextWriter(s);
     base.WriteJson(w, value, serializer);
     writer.WriteValue(s.ToString().ToLower().Trim('"'));
 }
开发者ID:sopel,项目名称:Salient.JsonClient,代码行数:7,代码来源:ApiEnumConverter.cs

示例13: WriteJson

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

            var obj = value as EthSyncing;

            if(obj.IsSynching)
            {
                writer.WriteStartObject();

                writer.WritePropertyName(StartingBlockKey);
                serializer.Serialize(writer, obj.StartingBlock.Value);

                writer.WritePropertyName(CurrentBlockKey);
                serializer.Serialize(writer, obj.CurrentBlock.Value);

                writer.WritePropertyName(HighestBlockKey);
                serializer.Serialize(writer, obj.HighestBlock.Value);

                writer.WriteEndObject();
            }
            else
            {
                writer.WriteValue(false);
            }
        }
开发者ID:TrekDev,项目名称:EthClient.NET,代码行数:30,代码来源:EthSyncingConverter.cs

示例14: WriteJson

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

            var target = new ClaimLite(source);
            serializer.Serialize(writer, target);
        }
开发者ID:Xamarui,项目名称:IdentityServer3.DocumentDb,代码行数:7,代码来源:ClaimConverter.cs

示例15: 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<IPosition>;
            if (coordinateElements != null && coordinateElements.Count > 0)
            {
                var coordinateArray = new JArray();

                foreach (var position in coordinateElements)
                {
                    // TODO: position types should expose a double[] coordinates property that can be used to write values 
                    var coordinates = (GeographicPosition)position;
                    var coordinateElement = new JArray(coordinates.Longitude, coordinates.Latitude);
                    if (coordinates.Altitude.HasValue)
                    {
                        coordinateElement = new JArray(coordinates.Longitude, coordinates.Latitude, coordinates.Altitude);
                    }

                    coordinateArray.Add(coordinateElement);
                }

                serializer.Serialize(writer, coordinateArray);
            }
            else
            {
                serializer.Serialize(writer, value);
            }
        }
开发者ID:tobiashoeft,项目名称:GeoJSON.Net,代码行数:33,代码来源:LineStringConverter.cs


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