public string ListString(JsonArray array) { string s = ""; if (array.Count > 0) { s += array.ElementAt(0); } for (int i = 1; i < array.Count; i++) { s += ", " + array.ElementAt(i); } return(s); }
private string ActorString(JsonArray info) { string s = ""; if (info.Count > 0) { s += info.ElementAt(0) ["name"]; } if (info.Count >= 1) { s += ", " + info.ElementAt(1) ["name"]; } return(s); }
public override JsonObject this [int position] { get { if (position == 0) //open header { return(null); } else if (position == open.Count + 1) //top header { return(null); } else if (position == open.Count + top.Count + 2) //also header { return(null); } else if (position < open.Count + 1) { return((JsonObject)open.ElementAt(position - 1)); } else if (position < open.Count + 2 + top.Count) { return((JsonObject)top.ElementAt(position - 2 - open.Count)); } else { return((JsonObject)also.ElementAt(position - 3 - open.Count - top.Count)); } } }
/// <summary> /// Populate the playlists information from the JSON object /// </summary> /// <param name="jsonString">The string representation of the playlist JSON object</param> /// <returns></returns> public async Task SetInfo(string jsonString) { JsonObject playlistJson = new JsonObject(); try { playlistJson = JsonObject.Parse(jsonString); } catch (COMException) { return; } if (playlistJson.TryGetValue("id", out IJsonValue idJson) && idJson.ValueType == JsonValueType.String) { id = idJson.GetString(); } if (playlistJson.TryGetValue("href", out IJsonValue hrefJson) && hrefJson.ValueType == JsonValueType.String) { href = hrefJson.GetString(); } if (playlistJson.TryGetValue("name", out IJsonValue nameJson) && nameJson.ValueType == JsonValueType.String) { name = nameJson.GetString(); } if (playlistJson.TryGetValue("owner", out IJsonValue ownerJson) && ownerJson.ValueType == JsonValueType.Object) { if (ownerJson.GetObject().TryGetValue("id", out IJsonValue ownerIdJson) && ownerIdJson.ValueType == JsonValueType.String) { owner = ownerIdJson.GetString(); } } if (playlistJson.TryGetValue("description", out IJsonValue descriptionJson) && descriptionJson.ValueType == JsonValueType.String) { description = Regex.Replace(descriptionJson.GetString(), "<.+?>", string.Empty); } if (playlistJson.TryGetValue("tracks", out IJsonValue tracksJson) && tracksJson.ValueType == JsonValueType.Object) { JsonObject trackJson = tracksJson.GetObject(); if (trackJson.TryGetValue("href", out IJsonValue trackHrefJson) && trackHrefJson.ValueType == JsonValueType.String) { tracksHref = trackHrefJson.GetString(); } if (trackJson.TryGetValue("total", out IJsonValue trackNumberJson) && trackNumberJson.ValueType == JsonValueType.Number) { tracksCount = Convert.ToInt32(trackNumberJson.GetNumber()); } } if (playlistJson.TryGetValue("images", out IJsonValue imagesJson) && imagesJson.ValueType == JsonValueType.Array) { JsonArray imagesArray = imagesJson.GetArray(); if (imagesArray.Count > 0) { JsonValue imageObject = imagesArray.ElementAt(0) as JsonValue; JsonValue urlJson = imageObject.GetObject().GetNamedValue("url"); string url = urlJson.GetString(); image = await RequestHandler.DownloadImage(url); } } }
private Dictionary <string, string> parseConfigs(JsonArray configsJson) { Dictionary <string, string> configs = new Dictionary <string, string>(); for (int i = 0; i < configsJson.Count; i++) { JsonObject c = configsJson.ElementAt(i) as JsonObject; configs.Add(c.getAsString("name"), c.getAsString("value")); } return(configs); }
private Dictionary<long, FriendsInfoStruct> ParseResults(JsonArray ResultsArray) { Dictionary<long, FriendsInfoStruct> FriendsInfo = new Dictionary<long, FriendsInfoStruct>(); JsonObject FriendsQuery = (JsonObject)ResultsArray.ElementAt(2); for (int i = 1; i < FriendsQuery.Count; i++) { JsonArray Friends = (JsonArray)FriendsQuery.ElementAt(i).Value; for (int j = 0; j < Friends.Count; j++) { JsonObject FriendJson = (JsonObject)Friends.ElementAt(j); string is_app_user = "******"; string name = ""; string pic_big = ""; string profile_update_time = "0"; string sex = ""; string uid = "0"; string wall_count = "0"; string pic_square = ""; string profile_url = ""; //Extended 1 string birthday_date = ""; string online_presence = "offline"; //active, idle, offline, or error string relationship_status = ""; string significant_other_id = "0"; //Extended 2 string status_message = ""; string status_time = ""; string current_location = ""; string website = ""; string third_party_id = ""; #region Standard if (FriendJson.ContainsKey("is_app_user")) if (FriendJson["is_app_user"] != null) is_app_user = FriendJson["is_app_user"].ToString(); if (FriendJson.ContainsKey("name")) if (FriendJson["name"] != null) name = FriendJson["name"].ToString(); if (FriendJson.ContainsKey("pic_big")) if (FriendJson["pic_big"] != null) pic_big = FriendJson["pic_big"].ToString(); if (FriendJson.ContainsKey("profile_update_time")) if (FriendJson["profile_update_time"] != null) profile_update_time = FriendJson["profile_update_time"].ToString(); if (FriendJson.ContainsKey("sex")) if (FriendJson["sex"] != null) sex = FriendJson["sex"].ToString(); if (FriendJson.ContainsKey("uid")) if (FriendJson["uid"] != null) uid = FriendJson["uid"].ToString(); if (FriendJson.ContainsKey("wall_count")) if (FriendJson["wall_count"] != null) wall_count = FriendJson["wall_count"].ToString(); if (FriendJson.ContainsKey("pic_square")) if (FriendJson["pic_square"] != null) pic_square = FriendJson["pic_square"].ToString(); if (FriendJson.ContainsKey("profile_url")) if (FriendJson["profile_url"] != null) profile_url = FriendJson["profile_url"].ToString(); #endregion #region Extended if (FriendJson.ContainsKey("birthday_date")) if (FriendJson["birthday_date"] != null) birthday_date = FriendJson["birthday_date"].ToString(); if (FriendJson.ContainsKey("online_presence")) if (FriendJson["online_presence"] != null) online_presence = FriendJson["online_presence"].ToString(); if (FriendJson.ContainsKey("relationship_status")) if (FriendJson["relationship_status"] != null) relationship_status = FriendJson["relationship_status"].ToString(); if (FriendJson.ContainsKey("significant_other_id")) if (FriendJson["significant_other_id"] != null) significant_other_id = FriendJson["significant_other_id"].ToString(); if (FriendJson.ContainsKey("status")) if (FriendJson["status"] != null) { var Status = FriendJson["status"] as JsonObject; if (Status[0] != null) { status_message = Status[0].ToString(); //string remomve = "[message, "; //status_message = status_message.Substring((remomve.Count() - 1), (status_message.Length - (remomve.Count()))); } if (Status[1] != null) { status_time = Status[1].ToString(); string remomve = "[time, "; status_time = status_time.Substring((remomve.Count() - 1), (status_time.Length - (remomve.Count()))); } } //if (FriendJson.ContainsKey("website")) // if (FriendJson["website"] != null) // website = FriendJson["website"].ToString(); //if (FriendJson.ContainsKey("third_party_id")) // if (FriendJson["third_party_id"] != null) // third_party_id = FriendJson["third_party_id"].ToString(); #endregion try { FriendsInfoStruct Friend = new FriendsInfoStruct(); Friend.Uid = long.Parse(uid); Friend.Name = name; bool isMale; if (sex == "female") isMale = false; else isMale = true; pic_big = Helpers.DefaultPictureBig(pic_big, isMale); Friend.Pic_Big_Url = Helpers.CleanHttps(pic_big); pic_square = Helpers.DefaultPictureSquare(pic_square, isMale); Friend.Pic_Sqaure_Url = Helpers.CleanHttps(pic_square); Friend.Profile_Url = Helpers.CleanHttps(profile_url); Friend.Profile_Update_Time = long.Parse(profile_update_time); Friend.Wall_Count = int.Parse(wall_count); Friend.Status_Time = status_time; Friend.Birthday_date = birthday_date; Friend.Sex = sex; Friend.Relationship_Status = relationship_status; Friend.Significant_Other_Id = long.Parse(significant_other_id); Friend.Is_App_User = bool.Parse(is_app_user); Friend.Status_Message = status_message; Friend.Status_Time = status_time; Friend.Online_Presence = online_presence; Friend.Current_Location = current_location; Friend.Webstie = website; Friend.Third_Party_Id = third_party_id; FriendsInfo.Add(Friend.Uid, Friend); } catch { Debug.WriteLine("Error @ Parse Friends Info"); } } } return FriendsInfo; }
/// <summary> /// Updates the users information (name, image, etc) /// </summary> /// <param name="jsonString">The JSON containing the users information</param> /// <returns></returns> public async static Task UpdateInfo(string jsonString) { // parse data JsonObject userJson = new JsonObject(); try { userJson = JsonObject.Parse(jsonString); } catch (COMException) { return; } if (userJson.TryGetValue("display_name", out IJsonValue displayNameJson) && displayNameJson.ValueType == JsonValueType.String) { displayName = displayNameJson.GetString(); } if (userJson.TryGetValue("id", out IJsonValue userIdJson) && userIdJson.ValueType == JsonValueType.String) { userId = userIdJson.GetString(); if (displayName == "") { displayName = userIdJson.GetString(); } } // picture if (userJson.TryGetValue("images", out IJsonValue imagesJson) && imagesJson.ValueType == JsonValueType.Array) { JsonArray imageArray = imagesJson.GetArray(); if (imageArray.Count > 0) { JsonObject imageObject = imageArray.ElementAt(0).GetObject(); JsonValue urlJson = imageObject.GetNamedValue("url"); string url = urlJson.GetString(); UriBuilder uri = new UriBuilder(url); BitmapImage bitmapImage = new BitmapImage(); HttpClient client = new HttpClient(); HttpResponseMessage httpResponse = new HttpResponseMessage(); try { httpResponse = await client.GetAsync(uri.Uri); httpResponse.EnsureSuccessStatusCode(); IInputStream st = await client.GetInputStreamAsync(uri.Uri); MemoryStream memoryStream = new MemoryStream(); await st.AsStreamForRead().CopyToAsync(memoryStream); memoryStream.Position = 0; await bitmapImage.SetSourceAsync(memoryStream.AsRandomAccessStream()); userPic = bitmapImage; SaveProfileData(); } catch (Exception) { } } } }
/// <summary> /// Populate the album information from the JSON object /// </summary> /// <param name="artistString">The string representation of the album JSON object</param> /// <returns></returns> public async Task SetInfo(string albumString) { JsonObject albumJson = new JsonObject(); try { albumJson = JsonObject.Parse(albumString); } catch (COMException) { return; } if (albumJson.TryGetValue("id", out IJsonValue idJson) && idJson.ValueType == JsonValueType.String) { id = idJson.GetString(); } if (albumJson.TryGetValue("name", out IJsonValue nameJson) && nameJson.ValueType == JsonValueType.String) { name = nameJson.GetString(); } if (albumJson.TryGetValue("href", out IJsonValue hrefJson) && hrefJson.ValueType == JsonValueType.String) { href = hrefJson.GetString(); // extra request to get release date UriBuilder fullUriBuilder = new UriBuilder(href); string fullString = await RequestHandler.SendCliGetRequest(fullUriBuilder.Uri.ToString()); JsonObject fullJson = new JsonObject(); try { fullJson = JsonObject.Parse(fullString); } catch (COMException) { return; } if (fullJson.TryGetValue("release_date", out IJsonValue releaseJson) && releaseJson.ValueType == JsonValueType.String) { releaseDate = releaseJson.GetString(); } } if (albumJson.TryGetValue("artists", out IJsonValue artistsJson) && artistsJson.ValueType == JsonValueType.Array) { JsonArray artistsArray = artistsJson.GetArray(); foreach (JsonValue artistObject in artistsArray) { Artist artist = new Artist(); artist.SetInfo(artistObject.Stringify()); artists.Add(artist); } } if (albumJson.TryGetValue("images", out IJsonValue imagesJson) && imagesJson.ValueType == JsonValueType.Array) { JsonArray imagesArray = imagesJson.GetArray(); if (imagesArray.Count > 0) { JsonValue imageObject = imagesArray.ElementAt(0) as JsonValue; JsonValue urlJson = imageObject.GetObject().GetNamedValue("url"); string url = urlJson.GetString(); imageUrl = url; image = await RequestHandler.DownloadImage(url); } } // need extra request to get total tracks UriBuilder tracksUriBuilder = new UriBuilder(string.Format(TRACKS_HREF, id)); List <KeyValuePair <string, string> > queryParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("limit", "1") }; string queryParamsString = RequestHandler.ConvertToQueryString(queryParams); tracksUriBuilder.Query = queryParamsString; string tracksString = await RequestHandler.SendCliGetRequest(tracksUriBuilder.Uri.ToString()); JsonObject tracksJson = new JsonObject(); try { tracksJson = JsonObject.Parse(tracksString); } catch (COMException) { return; } if (tracksJson.TryGetValue("total", out IJsonValue totalJson) && totalJson.ValueType == JsonValueType.Number) { tracksCount = Convert.ToInt32(totalJson.GetNumber()); } }