Пример #1
0
    static Page Parse(string pageJson)
    {
        var json   = JsonValue.Parse(pageJson)["recenttracks"];
        var attr   = json["@attr"];
        var tracks = json["track"];

        // It is json, yet Last.fm encodes integers as strings.
        var totalPages = Int32.Parse(attr["totalPages"]);
        var scrobbles  = new List <Scrobble>();

        foreach (JsonValue track in tracks)
        {
            var arn   = track["artist"]["name"];
            var arid  = track["artist"]["mbid"];
            var aln   = track["album"]["#text"];
            var alid  = track["album"]["mbid"];
            var tn    = track["name"];
            var tid   = track["mbid"];
            var time  = UnixTime.Parse(track["date"]["uts"]);
            var loved = track["loved"] == "1";
            scrobbles.Add(new Scrobble(arn, arid, aln, alid, tn, tid, time, loved));
        }

        return(new Page(totalPages, scrobbles.ToArray()));
    }