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


C# JsonReader.ReadAsString方法代码示例

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


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

示例1: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            string displayName = string.Empty;
            string address = string.Empty;
            while (reader.Read())
            {
                var tokenType = reader.TokenType;
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var val = (reader.Value as string )?? string.Empty;
                    if (val == "DisplayName")
                    {
                        displayName = reader.ReadAsString();
                    }
                    if (val == "Address")
                    {
                        address = reader.ReadAsString();
                    }
                }

                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }
            }

            var mailAddress = new MailAddress(address, displayName);
            return mailAddress;
        }
开发者ID:aduggleby,项目名称:dragon,代码行数:29,代码来源:MailAddressSerializerConverter.cs

示例2: ReadJson

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

            reader.Assert(JsonToken.StartObject);

            string toString = null;
            string idObj = null;
            string typeStr = null;
            Entity entity = null;

            reader.Read();
            while (reader.TokenType == JsonToken.PropertyName)
            {
                switch ((string)reader.Value)
                {
                    case "toStr": toString = reader.ReadAsString(); break;
                    case "id": idObj = reader.ReadAsString(); break;
                    case "EntityType": typeStr = reader.ReadAsString(); break;
                    case "entity":
                        reader.Read();
                        entity = (Entity)serializer.Deserialize(reader, typeof(Entity));
                        break;
                    default: throw new InvalidOperationException("unexpected property " + (string)reader.Value);
                }

                reader.Read();
            }

            reader.Assert(JsonToken.EndObject);

            Type type = TypeLogic.GetType(typeStr);

            PrimaryKey? idOrNull = idObj == null ? (PrimaryKey?)null : PrimaryKey.Parse(idObj, type);

            if (entity == null)
                return Lite.Create(type, idOrNull.Value, toString);

            var result = entity.ToLiteFat(toString);

            if (result.EntityType != type)
                throw new InvalidOperationException("Types don't match");

            if (result.IdOrNull != idOrNull)
                throw new InvalidOperationException("Id's don't match");

            var existing = existingValue as Lite<Entity>;

            if (existing.Is(result) && existing.EntityOrNull == null && result.EntityOrNull != null)
            {
                existing.SetEntity(result.EntityOrNull);
                return existing;
            }

           return result;
        }
开发者ID:signumsoftware,项目名称:framework,代码行数:57,代码来源:LiteJsonConverter.cs

示例3: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Debugger.Break();

            Source source = new Source();
            source.Format = reader.ReadAsString();
            source.Header = reader.ReadAsString();
            source.Link = reader.ReadAsString();
            return source;
        }
开发者ID:higankanshi,项目名称:MSDevUnion.BingWallpaper,代码行数:10,代码来源:SourceConverter.cs

示例4: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer )
        {
            if( typeof( DataCharacteristic ) == objectType )
            {
                var characteristic = new DataCharacteristic();
                if( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                {
                    characteristic.Uuid = new Guid( (string)reader.Value );

                    var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
                    if( reader.Read() && reader.TokenType == JsonToken.StartObject )
                    {
                        while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                        {
                            var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                            var value = reader.ReadAsString();

                            valueAttributes.Add( new DataService.Attribute( key, value ) );
                        }
                    }
                    characteristic.Value = new DataValue( valueAttributes.ToArray() );
                }
                return characteristic;
            }
            else
            {
                var characteristics = new System.Collections.Generic.List<DataCharacteristic>();
                while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                {
                    var characteristic = new DataCharacteristic();
                    characteristic.Uuid = new Guid( (string) reader.Value );

                    var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
                    if( reader.Read() && reader.TokenType == JsonToken.StartObject )
                    {
                        while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                        {
                            var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                            var value = reader.ReadAsString();

                            valueAttributes.Add( new DataService.Attribute( key, value ) );
                        }
                    }
                    characteristic.Value = new DataValue( valueAttributes.ToArray() );
                    characteristics.Add( characteristic );
                }
                return characteristics.ToArray();
            }
        }
开发者ID:darksun190,项目名称:PiWeb-Api,代码行数:52,代码来源:DataCharacteristicConverter.cs

示例5: ReadJson

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

            if( reader.TokenType != JsonToken.StartObject )
            {
                var msg = string.Join(" ",
                    $"The JSON representation of binary data (byte[]) when parsing the server response is not a {Converter.PseudoTypeKey}:{Converter.Binary} object.",
                    $"This happens if your JSON document contains binary data (byte[]) in some other format (like a base64 string only) rather than a native RethinkDB pseudo type {Converter.PseudoTypeKey}:{Converter.Binary} object.",
                    $"If you are overriding the default Ser/Deserialization process, you need to make sure byte[] is a native {Converter.PseudoTypeKey}:{Converter.Binary} objects before using the built-in {nameof(ReqlBinaryConverter)}.",
                    "See https://rethinkdb.com/docs/data-types/ for more information about how binary data is represented in RethinkDB.");
                throw new JsonSerializationException(msg);
            }

            reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
            var reql_type = reader.ReadAsString();
            if( reql_type != Converter.Binary )
            {
                throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.Binary} but got {reql_type}.");
            }

            reader.ReadAndAssertProperty("data");

            var data = reader.ReadAsBytes();

            //realign and get out of the pseudo type
            //one more post read to align out of { reql_type:BINARY, data:""} 
            reader.ReadAndAssert();

            return data;
        }
开发者ID:fjsnogueira,项目名称:RethinkDb.Driver,代码行数:34,代码来源:ReqlBinaryConverter.cs

示例6: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var filter = new TermsQueryDescriptor<object>();
			ITermsQuery f = filter;
			if (reader.TokenType != JsonToken.StartObject)
				return null;

			var depth = reader.Depth;
			while (reader.Read() && reader.Depth >= depth && reader.Value != null)
			{
				var property = reader.Value as string;
				switch (property)
				{
					case "boost":
						reader.Read();
						f.Boost = reader.Value as double?;
						break;
					case "_name":
						f.Name = reader.ReadAsString();
						break;
					default:
						f.Field = property;
						//reader.Read();
						ReadTerms(f, reader, serializer);
						//reader.Read();
						break;
				}
			}
			return filter;

		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:31,代码来源:TermsQueryJsonConverter.cs

示例7: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     var str = string.Empty;
     if (reader.TokenType != JsonToken.Null && reader.TokenType == JsonToken.String)
         str = reader.ReadAsString();
     return NamingConvention.FromString(str);
 }
开发者ID:neilunadkat,项目名称:appacitive-dotnet-sdk,代码行数:7,代码来源:EventTypeConverter.cs

示例8: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="Newtonsoft.Json.JsonReader"/> to read from.</param>
        /// <param name="objectType">The <see cref="System.Type"/> of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            switch(reader.TokenType)
            {
                case JsonToken.Integer:
                    return new Contributors { Id = (long)reader.Value };
                case JsonToken.StartObject:
                    reader.Read();
                    var value = new Contributors();
                    while(reader.TokenType != JsonToken.EndObject)
                    {
                        if(reader.TokenType != JsonToken.PropertyName)
                            throw new FormatException("The format of this object is wrong");

                        switch((string)reader.Value)
                        {
                            case "id":
                                value.Id = (long)reader.ReadAsDecimal();
                                break;
                            case "screen_name":
                                value.ScreenName = reader.ReadAsString();
                                break;
                            default:
                                reader.Read();
                                break;
                        }
                        reader.Read();
                    }
                    return value;
            }

            throw new InvalidOperationException("This object is not a Contributors");
        }
开发者ID:hinaloe,项目名称:CoreTweet,代码行数:41,代码来源:Converters.cs

示例9: DeserializeFromPackageJson

        public static DubProjectConfiguration DeserializeFromPackageJson(JsonReader j)
        {
            var c = new DubProjectConfiguration { Name = "<Undefined>" };

            var srz = new JsonSerializer();
            while (j.Read() && j.TokenType != JsonToken.EndObject)
            {
                if (j.TokenType == JsonToken.PropertyName)
                {
                    switch (j.Value as string)
                    {
                        case "name":
                            c.Name = c.Id = j.ReadAsString();
                            break;
                        case "platforms":
                            j.Read();
                            c.Platform = string.Join("|",srz.Deserialize<string[]>(j));
                            break;
                        default:
                            if (!c.BuildSettings.TryDeserializeBuildSetting(j))
                                j.Skip();
                            break;
                    }
                }
            }

            return c;
        }
开发者ID:simendsjo,项目名称:Mono-D,代码行数:28,代码来源:DubProjectConfiguration.cs

示例10: ReadJson

        //EXAMPLE:
        // "r": [
        //    {
        //    "$reql_type$": "GROUPED_DATA",
        //    "data": [
        //        [
        //          "Alice",
        //          [
        //            { "id": 5,  "player": "Alice", "points": 7, "type": "free"},
        //            { "id": 12, "player": "Alice", "points": 2, "type": "free" }
        //          ]
        //        ],
        //        [
        //          "Bob",
        //          [
        //            { "id": 2,  "player": "Bob", "points": 15, "type": "ranked" },
        //            { "id": 11, "player": "Bob", "points": 10, "type": "free" }
        //          ]
        //        ]
        //       ]
        //    }
        // ]
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
            var reql_type = reader.ReadAsString();
            if( reql_type != Converter.GroupedData )
            {
                throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.GroupedData} but got {reql_type}.");
            }
            
            reader.ReadAndAssertProperty("data");

            //move reader to property value
            reader.ReadAndAssert();

            //... probably find a better way to do this.
            var listType = typeof(List<>).MakeGenericType(objectType);

            var list = (IList)Activator.CreateInstance(listType);

            var data = serializer.Deserialize<List<JArray>>(reader);
            foreach( var group in data )
            {
                var key = group[0]; //key, group value in common
                var items = group[1]; //the grouped items
                var grouping = Activator.CreateInstance(objectType, key, items);
                list.Add(grouping);
            }
            //.Select(arr => Activator.CreateInstance(objectType, arr) ).ToList();

            return list;
        }
开发者ID:gitter-badger,项目名称:RethinkDb.Driver,代码行数:53,代码来源:ReqlGroupingConverter.cs

示例11: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.String)
     {
         return new AssemblyName(reader.ReadAsString());
     }
     return null;
 }
开发者ID:stephenosrajan,项目名称:NuGet.Services.Platform,代码行数:8,代码来源:AssemblyFullNameConverter.cs

示例12: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
 {
     var result = new TwitterRateLimitStatusSummary();
     reader.Read();
     reader.Read();
     reader.Read();
     result.AccessToken = reader.ReadAsString(); // access_token
     return result;
 }
开发者ID:FrenchW,项目名称:tweetmoasharp,代码行数:9,代码来源:TwitterGeoConverter.cs

示例13: ReadJson

 public override object ReadJson(
     JsonReader reader,
     Type objectType,
     object existingValue,
     JsonSerializer serializer)
 {
     var webColorString = reader.ReadAsString();
     return new WebColor(webColorString);
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:9,代码来源:WebColorConverter.cs

示例14: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var s = reader.ReadAsString();
			switch(s)
			{
				case "keep": return ReindexRouting.Keep;
				case "discard": return ReindexRouting.Discard;
				default: return new ReindexRouting(s);
			}
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:10,代码来源:ReindexRoutingJsonConverter.cs

示例15: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            //reader.Read();
            var obj = new Filter();
            obj.Name = reader.ReadAsString();
            obj.Count = reader.ReadAsInt32().GetValueOrDefault();

            reader.Read();

            return obj;
        }
开发者ID:illallangi-ps,项目名称:Deluge,代码行数:11,代码来源:FilterJsonConverter.cs


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