/// <summary> /// Reads the json. /// </summary> /// <param name="reader">The reader.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value.</param> /// <param name="serializer">The serializer.</param> /// <returns>A collection of <see cref="TwitterTrend"/> items.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { TwitterTrendLocationCollection result = existingValue as TwitterTrendLocationCollection; if (result == null) { result = new TwitterTrendLocationCollection(); } int initialDepth = reader.Depth; while (reader.Read() && reader.Depth > initialDepth) { if (reader.TokenType == JsonToken.StartObject && reader.Depth >= 1) { result.Add(new TwitterTrendLocation()); } if (reader.TokenType == JsonToken.PropertyName) { switch ((string)reader.Value) { case "name": reader.Read(); result[result.Count - 1].Name = (string)reader.Value; continue; case "woeid": reader.Read(); result[result.Count - 1].WOEID = int.Parse(reader.Value.ToString()); continue; case "placeType": int placetypeDepth = reader.Depth; while (reader.Read() && reader.Depth > placetypeDepth) { if (reader.TokenType == JsonToken.StartObject && reader.Depth >= 2) { result[result.Count - 1].PlaceType = new TwitterTrendLocationPlaceType(); } if (reader.TokenType == JsonToken.PropertyName) { switch ((string)reader.Value) { case "name": reader.Read(); result[result.Count - 1].PlaceType.Name = (string)reader.Value; continue; case "code": reader.Read(); result[result.Count - 1].PlaceType.Code = int.Parse(reader.Value.ToString()); continue; } } } continue; case "country": reader.Read(); result[result.Count - 1].Country = (string)reader.Value; continue; case "url": reader.Read(); result[result.Count - 1].URL = (string)reader.Value; continue; case "countryCode": reader.Read(); result[result.Count - 1].CountryCode = (string)reader.Value; continue; } } } return(result); }
private async void LoadTrends() { this.ShowErrorPanel = false; this.ShowAnimation = true; this.ShowTrendsList = false; if (this.trendsGroupType == TrendsGroupType.Current) { if (App.AvailableTrendLocations == null) { TwitterResponse<TwitterTrendLocationCollection> asyncVariable0 = await Trends.AvailableAsync(App.AppState.CurrentActiveAccount.Tokens, MetroTwitTwitterizer.AvailableTrendsOptions); if (asyncVariable0.Result == RequestResult.Success) { TwitterTrendLocationCollection responseObject = asyncVariable0.ResponseObject; TwitterTrendLocationCollection oc = new TwitterTrendLocationCollection(); oc.AddRange<TwitterTrendLocation>((from tt in responseObject orderby tt.Name select tt).ToList<TwitterTrendLocation>()); TwitterTrendLocation item = (from ttl in oc where ttl.Name.ToLower() == "worldwide" select ttl).FirstOrDefault<TwitterTrendLocation>(); if (item != null) { oc.Remove(item); oc.Insert(0, item); } App.AvailableTrendLocations = oc; if (this.AvailableTrendLocations == null) { this.AvailableTrendLocations = oc; } this.SetLocalLocation(); } } else { if (this.AvailableTrendLocations == null) { this.AvailableTrendLocations = App.AvailableTrendLocations; } this.SetLocalLocation(); } } }