From 07a5fab0599756356d1714eafc62efefc9db79bb Mon Sep 17 00:00:00 2001 From: Harry Date: Wed, 22 Oct 2014 09:49:44 -0400 Subject: [PATCH] Fix tags bugs for last objects Needed to check if the token was an array or not and continue from there to the appropriate action. --- src/IF.Lastfm.Core/Objects/LastAlbum.cs | 7 ++++++- src/IF.Lastfm.Core/Objects/LastArtist.cs | 11 +++++++++-- src/IF.Lastfm.Core/Objects/LastTrack.cs | 11 +++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/IF.Lastfm.Core/Objects/LastAlbum.cs b/src/IF.Lastfm.Core/Objects/LastAlbum.cs index 78d51fe1..4c1434e8 100644 --- a/src/IF.Lastfm.Core/Objects/LastAlbum.cs +++ b/src/IF.Lastfm.Core/Objects/LastAlbum.cs @@ -71,7 +71,12 @@ internal static LastAlbum ParseJToken(JToken token) { var tagToken = tagsToken.SelectToken("tag"); if (tagToken != null) - a.TopTags = tagToken.Children().Select(LastTag.ParseJToken); + { + a.TopTags = + tagToken.Type == JTokenType.Array + ? tagToken.Children().Select(LastTag.ParseJToken) + : new List { LastTag.ParseJToken(tagToken) }; + } } a.ListenerCount = token.Value("listeners"); diff --git a/src/IF.Lastfm.Core/Objects/LastArtist.cs b/src/IF.Lastfm.Core/Objects/LastArtist.cs index 262c9b10..b1b5128b 100644 --- a/src/IF.Lastfm.Core/Objects/LastArtist.cs +++ b/src/IF.Lastfm.Core/Objects/LastArtist.cs @@ -41,9 +41,16 @@ internal static LastArtist ParseJToken(JToken token) a.OnTour = Convert.ToBoolean(token.Value("ontour")); var tagsToken = token.SelectToken("tags"); - if (tagsToken != null && tagsToken.HasValues) + if (tagsToken != null) { - a.Tags = tagsToken.SelectToken("tag").Children().Select(LastTag.ParseJToken); + var tagToken = tagsToken.SelectToken("tag"); + if (tagToken != null) + { + a.Tags = + tagToken.Type == JTokenType.Array + ? tagToken.Children().Select(LastTag.ParseJToken) + : new List { LastTag.ParseJToken(tagToken) }; + } } var images = token.SelectToken("image"); diff --git a/src/IF.Lastfm.Core/Objects/LastTrack.cs b/src/IF.Lastfm.Core/Objects/LastTrack.cs index 23ad5a42..a69da37d 100644 --- a/src/IF.Lastfm.Core/Objects/LastTrack.cs +++ b/src/IF.Lastfm.Core/Objects/LastTrack.cs @@ -66,9 +66,16 @@ internal static LastTrack ParseJToken(JToken token) } var tagsToken = token.SelectToken("toptags"); - if (tagsToken != null && tagsToken.HasValues) + if (tagsToken != null) { - t.TopTags = tagsToken.SelectToken("tag").Children().Select(LastTag.ParseJToken); + var tagToken = tagsToken.SelectToken("tag"); + if (tagToken != null) + { + t.TopTags = + tagToken.Type == JTokenType.Array + ? tagToken.Children().Select(LastTag.ParseJToken) + : new List { LastTag.ParseJToken(tagToken) }; + } } var date = token.SelectToken("date");