• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Newtonsoft类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return null;
            }

            if (reader.TokenType != JsonToken.StartArray)
            {
                return null;
            }
            reader.Read();
            var coords = new double[2];
            for (int i = 0; i < 2; ++i)
            {
                if (reader.TokenType == JsonToken.Float)
                {
                    coords[i] = (double)reader.Value;
                    reader.Read();
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    coords[i] = (double)((long)reader.Value);
                    reader.Read();
                }
            }

            var latitude = coords[0];
            var longitude = coords[1];

            return new TwitterGeoLocation.GeoCoordinates { Latitude = latitude, Longitude = longitude };
        }
开发者ID:RobertChrist,项目名称:tweetsharp,代码行数:32,代码来源:TwitterGeoConverter.cs


示例17: Position

 internal Position(Newtonsoft.Json.Linq.JToken json)
     : this()
 {
     InstrumentUrl = new Url<Account>((string)json["instrument"]);
       AverageBuyPrice = (decimal)json["average_buy_price"];
       Quantity = (decimal)json["quantity"];
 }
开发者ID:itsff,项目名称:RobinhoodNet,代码行数:7,代码来源:Position.cs


示例18: WriteJson

 public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
 {
     if (value != null)
     {
         writer.WriteValue((((bool) value) ? 1 : 0).ToString(CultureInfo.InvariantCulture));
     }
 }
开发者ID:rangab,项目名称:Magento-RestApi,代码行数:7,代码来源:BoolConverter.cs


示例19: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            FunctionInputOutput functionInputOutput = new FunctionInputOutput();
            int startingDepth = reader.Depth;

            while (!(reader.TokenType == JsonToken.EndObject && reader.Depth == startingDepth))
            {
                reader.Read();
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    string propertyName = reader.Value.ToString();

                    if (String.Equals(propertyName, "name"))
                    {
                        reader.Read();
                        functionInputOutput.Name = reader.Value.ToString();
                    }
                    else if (String.Equals(propertyName, "type"))
                    {
                        reader.Read();
                        functionInputOutput.Type = reader.Value.ToString();
                    }
                }
            }

            return functionInputOutput;
        }
开发者ID:TrekDev,项目名称:EthClient.NET,代码行数:27,代码来源:FunctionInputOutputConverter.cs


示例20: Read

        public object Read(Newtonsoft.Json.JsonReader reader)
        {
            if (reader.TokenType != Newtonsoft.Json.JsonToken.StartObject)
                throw new Exception();

            int w = ReadIntProperty(reader, "Width");
            int h = ReadIntProperty(reader, "Height");
            int d = ReadIntProperty(reader, "Depth");

            var grid = new TileData[d, h, w];

            reader.Read();
            if (reader.TokenType != Newtonsoft.Json.JsonToken.PropertyName || (string)reader.Value != "TileData")
                throw new Exception();

            ReadAndValidate(reader, Newtonsoft.Json.JsonToken.StartArray);

            var queue = new BlockingCollection<Tuple<int, byte[]>>();

            var readerTask = Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < d; ++i)
                {
                    reader.Read();
                    int z = (int)(long)reader.Value;

                    byte[] buf = reader.ReadAsBytes();

                    queue.Add(new Tuple<int, byte[]>(z, buf));
                }

                queue.CompleteAdding();
            });

            Parallel.For(0, d, i =>
            {
                var tuple = queue.Take();

                int z = tuple.Item1;
                byte[] arr = tuple.Item2;

                using (var memStream = new MemoryStream(arr))
                {
                    using (var decompressStream = new DeflateStream(memStream, CompressionMode.Decompress))
                    using (var streamReader = new BinaryReader(decompressStream))
                    {
                        for (int y = 0; y < h; ++y)
                            for (int x = 0; x < w; ++x)
                                grid[z, y, x].Raw = streamReader.ReadUInt64();
                    }
                }
            });

            readerTask.Wait();

            ReadAndValidate(reader, Newtonsoft.Json.JsonToken.EndArray);
            ReadAndValidate(reader, Newtonsoft.Json.JsonToken.EndObject);

            return grid;
        }
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:60,代码来源:TileGridReaderWriter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NextAction类代码示例发布时间:2022-05-24
下一篇:
C# News类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap