/// <summary>
            /// Reads the JSON representation of the object.
            /// </summary>
            /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
            /// <param name="objectType">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)
            {
                TwitterPlaceCollection result = new TwitterPlaceCollection();

                reader.Read();
                reader.Read();

                bool hasReachedTheQuery = false;

                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "query")
                    {
                        hasReachedTheQuery = true;
                    }

                    if (hasReachedTheQuery)
                    {
                        continue;
                    }

                    if (reader.TokenType == JsonToken.StartObject)
                    {
                        result.Add(serializer.Deserialize <TwitterPlace>(reader));
                    }
                }

                return(result);
            }
Ejemplo n.º 2
0
        public static void LookupPlaces()
        {
            TwitterPlaceLookupOptions options = new TwitterPlaceLookupOptions
            {
                Granularity = "city",
                MaxResults  = 2
            };

            TwitterPlaceCollection places = TwitterPlace.Lookup(30.475012, -84.35509, options).ResponseObject;

            Assert.IsNotNull(places);
            Assert.IsNotEmpty(places);
            Assert.That(places.Count == 2);
        }