public static YandexPlaylist FromJson(JToken jList) { var playlist = new YandexPlaylist { Collective = jList.GetBool("collective"), Cover = jList.ContainField("cover") ? YandexCover.FromJson(jList["cover"]) : null, Description = jList.GetString("description"), DescriptionFormatted = jList.GetString("descriptionFormatted"), Duration = jList.GetInt("Duration"), GeneratedPlaylistType = jList.GetString("generatedPlaylistType"), IdForFrom = jList.GetString("IdForFrom"), Kind = jList.GetInt("kind"), LikesCount = jList.GetInt("likesCount"), Modified = jList.GetString("modified"), OgImage = jList.GetString("ogImage"), Owner = jList.ContainField("owner") ? YandexOwner.FromJson(jList["owner"]) : null, Revision = jList.GetInt("revision"), Title = jList.GetString("title"), TrackCount = jList.GetInt("trackCount"), Visibility = jList.GetString("visibility"), TrackIds = jList.ContainField("trackIds") ? jList["trackIds"].Select(x => int.Parse(x.ToString())).ToList() : null, Tracks = jList.ContainField("tracks") ? YandexTrack.FromJsonArray(jList["tracks"].ToObject <JArray>()) : null }; return(playlist); }
public static YandexAlbum FromJson(JToken jAlbum) { var album = new YandexAlbum { Artists = YandexArtist.FromJsonArray(jAlbum["artists"].ToObject <JArray>()), Available = jAlbum.GetBool("available"), AvailableForPremiumUsers = jAlbum.GetBool("availableForPremiumUsers"), CoverUri = jAlbum.GetString("coverUri"), Genre = jAlbum.GetString("genre"), Id = jAlbum.GetString("id"), OriginalReleaseYear = jAlbum.GetString("originalReleaseYear"), Regions = jAlbum.Contains("regions") ? jAlbum["regions"].ToObject <JArray>().Select(x => (string)x).ToList() : null, StorageDir = jAlbum.GetString("storageDir"), Title = jAlbum.GetString("title"), TrackCount = jAlbum.GetInt("trackCount"), Year = jAlbum.GetString("year"), Bests = jAlbum.ContainField("bests") ? jAlbum["bests"].ToObject <JArray>().Select(x => x.ToString()).ToList() : null, Type = jAlbum.GetString("type"), }; if (jAlbum.ContainField("volumes")) { if (jAlbum["volumes"].ToString() != String.Empty) { var fieldVolumes = jAlbum["volumes"].ToObject <JArray>().FirstOrDefault(); if (fieldVolumes != null) { var jVolumes = fieldVolumes.ToObject <JArray>(); var tracks = YandexTrack.FromJsonArray(jVolumes); album.Volumes = new List <List <YandexTrack> > { tracks }; } else { album.Volumes = null; } } } // album.Volumes = jAlbum.ContainField("volumes") // ? new List<List<Track>> // { // Track.FromJsonArray(jAlbum["volumes"].ToObject<JArray>().First().ToObject<JArray>()) // } // : null; return(album); }