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


C# Newtonsoft类代码示例

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


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

示例1: Parse

 protected override void Parse(Newtonsoft.Json.Linq.JToken json)
 {
     base.Parse(json);
     this.Id = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseSimpleValue<int>(json, "id");
     this.Label = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseSimpleValue<string>(json, "label");
     this.ParseExtension(json);
 }
开发者ID:mjeanrichard,项目名称:XBMC-Net-Library,代码行数:7,代码来源:CurrentWindow.cs

示例2: CreateProperties

        protected override IList<JsonProperty> CreateProperties(Type type, Newtonsoft.Json.MemberSerialization memberSerialization)
        {
            var properties = base.CreateProperties(type, memberSerialization);
            if (properties.Count > 0)
            {
                foreach (var property in type.GetProperties())
                {
                    var sensitiveDataAttributes = property.GetCustomAttributes(typeof(SensitiveDataAttribute), false);
                    if (!sensitiveDataAttributes.Any()) { continue; }

                    var mappedProperty = properties.FirstOrDefault(p => p.UnderlyingName == property.Name);
                    if (mappedProperty != null)
                    {
                        var attribute = (sensitiveDataAttributes[0] as SensitiveDataAttribute);
                        if (attribute.Direction == Direction.Output)
                            properties.Add(GetJsonProperty(type, mappedProperty, attribute));
                        else
                        {
                            mappedProperty.ValueProvider = new SensitiveDataValueProvider(property.Name, SaltGenerator);
                        }
                    }
                }
            }
            return properties;
        }
开发者ID:BikS2013,项目名称:bUtility,代码行数:25,代码来源:SensitiveDataContractResolver.cs

示例3: 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">Serializer</param>
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is DateTime || value is DateTime?)
            {
                DateTime date = value is DateTime ? (DateTime)value : (value as DateTime?).Value;

                if (date != DateTime.MinValue)
                {
                    writer.WriteValue(date.ToString(this.RenderMilliseconds ? DateTimeFormatMs : DateTimeFormat, CultureInfo.InvariantCulture));
                }
                else
                {
                    writer.WriteRawValue("null");
                }

                return;
            }
            else
            {
                DateTimeOffset dateTimeOffset = (DateTimeOffset)value;

                if (dateTimeOffset != DateTimeOffset.MinValue)
                {
                    writer.WriteValue(dateTimeOffset.ToString(DateTimeFormat, CultureInfo.InvariantCulture));
                }
                else
                {
                    writer.WriteRawValue("null");
                }
            }

            writer.WriteRawValue("null");
        }
开发者ID:emayk,项目名称:Ext.NET.Pro,代码行数:39,代码来源:JSONDateTimeJsonConverter.cs

示例4: ReadJson

		public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			if (reader.ValueType == null)
			{
				var obj = JObject.Load(reader);
				Type type = null;
				var typeToken = obj["$type"];
				if (typeToken != null)
				{
					string assemblyName = null;
					var typeName = typeToken.Value<string>();
					var assemblyIndex = typeName.IndexOf(',');
					if (assemblyIndex > 0)
					{
						assemblyName = typeName.Substring(assemblyIndex + 1).Trim();
						typeName = typeName.Substring(0, assemblyIndex);
					}
					type = serializer.Binder.BindToType(assemblyName, typeName);
				}
				else
					type = objectType;

				var target = Activator.CreateInstance(type);
				serializer.Populate(obj.CreateReader(), target);
				return target;
			}
			if (objectType == reader.ValueType)
				return reader.Value;
			var converter = GetConverter(objectType, reader.ValueType);
			if (converter != null)
			{
				return converter.ConvertFrom(reader.Value);
			}
			return reader.Value;
		}
开发者ID:mhusen,项目名称:Eto,代码行数:35,代码来源:TypeConverterConverter.cs

示例5: Parse

 protected override void Parse(Newtonsoft.Json.Linq.JToken json)
 {
     base.Parse(json);
     this.Art = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseJsonObject<Media.Artwork>(json, "art");
     this.PlayCount = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseSimpleValue<System.Nullable<int>>(json, "playcount", 0);
     this.ParseExtension(json);
 }
开发者ID:mjeanrichard,项目名称:XBMC-Net-Library,代码行数:7,代码来源:Base.cs

示例6: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            bool isNullableType = (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof (Nullable<>));
            object value = reader.Value;

            DateTime result;
            if (value is DateTime)
            {
                result = (DateTime) value;
            }
            else if (value is string)
            {
                // ISO 8601 String
                result = DateTime.Parse((string) value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
            }
            else if (value is long)
            {
                // UNIX epoch timestamp (in seconds)
                result = UnixEpochBase.AddSeconds((long) value);
            }
            else
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Deserializing {0} back to {1} is not handled.", value.GetType().FullName, objectType.FullName));
            }

            if (isNullableType && result == default(DateTime))
            {
                return null; // do not set result on DateTime? field
            }

            return result;
        }
开发者ID:onecityuni,项目名称:Docker.DotNet,代码行数:32,代码来源:JsonIso8601AndUnixEpochDateConverter.cs

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

示例8: WriteJson

 public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value is int[])
     {
         writer.WriteRawValue("[{0}]".FormatWith(((int[])value).Join(",", "{0}")));
     }
 }
开发者ID:emayk,项目名称:Ext.NET.Pro,代码行数:7,代码来源:IntArrayJsonConverter.cs

示例9: WriteJson

        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is ComponentListener)
            {
                ComponentListener componentListener = (ComponentListener)value;

                if (!componentListener.IsDefault)
                {
                    if (this.Owner is BaseItem)
                    {
                        componentListener.Owner = ((BaseItem)this.Owner).Owner;
                    }
                    else if (this.Owner is Control) 
                    {
                        componentListener.Owner = (Control)this.Owner;
                    }

                    if (this.PropertyName.IsNotEmpty())
                    {
                        componentListener.SetArgumentList(this.Owner.GetType().GetProperty(this.PropertyName));
                    }
                    
                    writer.WriteRawValue(new ClientConfig().Serialize(componentListener));
                    return;
                }
            }
            writer.WriteRawValue("{}");
        }
开发者ID:rajjan,项目名称:Ext.NET.Community,代码行数:28,代码来源:ListenerJsonConverter.cs

示例10: WriteJson

 public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value is string)
     {
         writer.WriteRawValue(new JFunction((string)value).ToScript()); 
     }
 }
开发者ID:hpj1106,项目名称:Ext.NET.Community,代码行数:7,代码来源:FunctionJsonConverter.cs

示例11: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer )
        {
            if( typeof( DataService.Attribute ) == objectType )
            {
                var result = default( DataService.Attribute );
                if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName )
                {
                    var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                    var value = reader.ReadAsString();

                    result = new DataService.Attribute( key, value );
                }
                return result;
            }
            else
            {
                var result = new List<DataService.Attribute>();
                if( reader.TokenType == Newtonsoft.Json.JsonToken.StartObject )
                {
                    while( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName )
                    {
                        var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                        var value = reader.ReadAsString();

                        result.Add( new DataService.Attribute( key, value ) );
                    }
                }
                return result.ToArray();
            }
        }
开发者ID:darksun190,项目名称:PiWeb-Api,代码行数:33,代码来源:AttributeConverter.cs

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

示例13: CreateProperty

        //protected override JsonContract CreateContract(Type objectType)
        //{
        //    JsonContract contract = base.CreateContract(objectType);
        //    // this will only be called once and then cached
        //    if (objectType.IsValueType || objectType.IsEnum || objectType == typeof(string))
        //        return contract;
        //    if (objectType.GetInterface("IEnumerable") != null)
        //        throw new ArgumentException("IEnumerable should not serialize!");
        //    contract.Converter = new EntityIdConverter();
        //    return contract;
        //}
        protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, Newtonsoft.Json.MemberSerialization memberSerialization)
        {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            var propertyType = property.PropertyType;
            if (propertyType.IsValueType || propertyType == typeof(string))
            {
            }
            else if (propertyType.IsEnum)
            {
                //property.Converter = new Newtonsoft.Json.Converters.StringEnumConverter();
            }
            else if (propertyType.GetInterface("IEnumerable") != null)
            {
                property.ShouldSerialize =
                  instance =>
                  {
                      return false;
                  };
            }
            else
            {
                property.Converter = new EntityIdConverter();
            }
            return property;
        }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:37,代码来源:RealToWSJsonConverterContractResolver.cs

示例14: ParseJson

            public override void ParseJson(DbGeographyGeoJsonConverter converter, Newtonsoft.Json.Linq.JArray array)
            {
                var targetCoordinateSystem = (converter as EpsgDbGeometryConverter).CoordinateSystem;
                //Cant convert if source dont have any coordinate system.
                if (!CoordinateSystem.HasValue ||  CoordinateSystem == targetCoordinateSystem)
                {
                    base.ParseJson(converter, array);
                    return;
                }

                Rings = new List<List<Position>>();
                var rings = array.ToObject<double[][][]>();

                var ringSizes = rings.Select(r => r.Length).ToArray();
                var coordinateLength = rings.First().GroupBy(c => c.Length).Single().Key;
                foreach (var ring in rings)
                {
                    var flat = ring.SelectMany(s => s).ToArray();

                    Reproject.ReprojectPoints(flat, null,
                     ProjectionInfo.FromEpsgCode(CoordinateSystem.Value), ProjectionInfo.FromEpsgCode(targetCoordinateSystem.Value), 0, ringSizes[0]);

                    var ringList = new List<Position>();
                    for (int i = 0; i < flat.Length; i += coordinateLength)
                        ringList.Add(new Position(flat.Skip(i).Take(coordinateLength).ToArray()));
                    Rings.Add(ringList);
                }
                CoordinateSystem = targetCoordinateSystem;
            }
开发者ID:crazymouse0,项目名称:gis,代码行数:29,代码来源:EpsgDbGeometryConverter.cs

示例15: Parse

 protected override void Parse(Newtonsoft.Json.Linq.JToken json)
 {
     base.Parse(json);
     this.Channelgroupid = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseSimpleValue<System.Nullable<int>>(json, "channelgroupid", -1);
     this.Channeltype = JeanRichard.Xbmc.Lib.JsonHelpers.JObjectExtensions.ParseEnum<PVR.Channel.Type>(json, "channeltype", PVR.Channel.Type.TV);
     this.ParseExtension(json);
 }
开发者ID:mjeanrichard,项目名称:XBMC-Net-Library,代码行数:7,代码来源:Channelgroup.cs


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