當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。