iOS: Läsa från Lastfm

Tråden skapades och har fått 7 svar. Det senaste inlägget skrevs .
1

Jag ska plocka ut bilden från Lastfm-svaret... men nu orkar jag inte tänka mer idag.

Här det är det långa härliga svaret som en NSDictionary.
Men när jag letar efter nyckeln image kammar jag noll, eller någon annan nyckel för den delen.

Hur kommer jag åt bilden som är extralarge, jag behöver dess URL.

lastfm: {
    track =     {
        album =         {
            "@attr" =             {
                position = 1;
            };
            artist = Cher;
            image =             (
                                {
                    "#text" = "http://userserve-ak.last.fm/serve/64s/4116148...";
                    size = small;
                },
                                {
                    "#text" = "http://userserve-ak.last.fm/serve/126/4116148...";
                    size = medium;
                },
                                {
                    "#text" = "http://userserve-ak.last.fm/serve/174s/411614...";
                    size = large;
                },
                                {
                    "#text" = "http://userserve-ak.last.fm/serve/300x300/411...";
                    size = extralarge;
                }
            );
            mbid = "00d677bf-46f2-34a4-86ad-e922d8466943";
            title = "The Very Best of Cher";
            url = "http://www.last.fm/music/Cher/The+Very+Best+o...";
        };
        artist =         {
            mbid = "bfcc6d75-a6a5-4bc6-8282-47aec8531818";
            name = Cher;
            url = "http://www.last.fm/music/Cher";
        };
        duration = 222000;
        id = 1019817;
        listeners = 275151;
        mbid = "028523f5-23b3-4910-adc1-46d932e2fb55";
        name = Believe;
        playcount = 1140882;
        streamable =         {
            "#text" = 1;
            fulltrack = 0;
        };
        toptags =         {
            tag =             (
                                {
                    name = pop;
                    url = "http://www.last.fm/tag/pop";
                },
                                {
                    name = dance;
                    url = "http://www.last.fm/tag/dance";
                },
                                {
                    name = 90s;
                    url = "http://www.last.fm/tag/90s";
                },
                                {
                    name = cher;
                    url = "http://www.last.fm/tag/cher";
                },
                                {
                    name = "female vocalists";
                    url = "http://www.last.fm/tag/female%20vocalists";
                }
            );
        };
        url = "http://www.last.fm/music/Cher/_/Believe";
        wiki =         {
            content = ""Believe" is a Grammy Award winning global number one, Multi-Platinum Dance Song which served as the world-wide lead single for American singer Cher's twenty-third studio album Believe. It is noted for its use of a peculiar sound effect on the singer's vocals, which is referred to as the Cher effect today.\n \n "Believe" was written by a number of writers including Paul Barry, Matt Gray, Brian Higgins, Stuart McLellan, Timothy Powell, and Steven Torch. The song, released and recorded in 1998, peaked at number one in 23 countries worldwide .In the second week of March, 1999, it reached number one in the Billboard Hot 100, making Cher the oldest female artist (at the age of 52) to perform this feat. It also was ranked as the number-one song of 1999 by Billboard, and became the biggest single in her entire career. "Believe" also spent seven weeks at number one] in the UK singles chart and is still the best selling single by a female artist in the UK. \n \n \n In March 2007, the United World Chart ranked "Believe" as the sixteenth most successful song in music history. The same chart lists "Believe" as third most successful song released by a solo female musician behind Whitney Houston's "I Will Always Love You" and Celine Dion's My Heart Will Go On; [5], the biggest selling single ever for Warner Bros. Records and the biggest selling dance song ever having sold over 10 million copies worldwide. It was also the song with most weeks in the top ten, it stayed in the top ten for 28 weeks.\n \n The success of the song not only expanded through each country's singles chart, but also most country's dance charts. In the United States "Believe" spent 23 weeks on the U.S. Hot Dance Club Play chart and 22 weeks on the European Hot Dance Charts. "Believe" also set a record in 1999 after spending 21 weeks in the top spot of the Billboard Hot Dance Singles Sales chart, it was still in the top ten even one year after its entry on the chart. \n \n "Believe" was given the featured closing number spot for over 100 performances on Cher's 1999-2000 Do You Believe? Tour and then again the closing spot for over 300 performances on Cher's epic 2002-2005 Living Proof: The Farewell Tour. The song ranked #74 on VH1's 100 Greatest Songs of the 90s.\n \n An interesting note about the recording of the song revolved around the highly-recognizable Auto-tune effect ("Cher effect") utilized in the verses and chorus. Producer Mark Taylor added the effect to Cher's vocal simply as a lark, and in interviews at the time, he claimed to be testing out his recently purchased the 'DigiTech Talker'. However, it later emerged that the effect was not created by a vocoder, but by utilizing extreme (and then unheard) settings on auto-tune.When Cher heard the results, she demanded that the effect remain in the song, and her original vocal be erased, much to the chagrin of her record company, who wanted it removed; upon their suggestion, Cher's response to the record label was "over my dead body!"[citation needed] The vocal effect is caused by a pitch correction speed that is "set too fast for the audio that it is processing." \n \n \n U.S. Billboard Hot 100 Airplay\t1\n U.S. Billboard Hot 100\t1\n U.S. Billboard Hot Dance Club Play\t1\n U.S. Billboard Hot Dance Singles Sales\t1\n U.S. Billboard Hot Adult Contemporary Tracks\t2\n U.S. Billboard Hot Adult Top 40 Tracks\t2\n U.S. Billboard Top 40 Mainstream\t2\n Argentinian Singles Chart\t2\n Australian ARIA Singles Chart\t1\n Austrian Singles Chart\t2\n Belgian Singles Chart\t1\n Brazilian Airplay Chart\t1\n Croatian Singles Chart\t1\n Canadian Singles Chart\t1\n Danish Singles Chart\t1\n Dutch Mega Top 50 Singles Chart\t1\n Dutch Top 40\t1\n European Singles Chart\t1\n Finnish Singles Chart\t6\n French Singles Chart\t1\n German Singles Chart\t1\n Irish Singles Chart\t1\n Israeli Singles Chart\t1\n Italian Singles Chart\t1\n Latvian Singles Chart\t1\n Mexican Singles Chart\t1\n New Zealand's Singles Chart\t1\n Norwegian Singles Chart\t1\n Polish Singles Chart\t1\n Spanish Singles Chart\t1\n Swedish Singles Chart\t1\n Swedish Airplay Chart\t1\n Swiss Singles Chart\t1\n UK Singles Chart\t1\n United World Chart\t1\n \n        \nUser-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.";
            published = "Tue, 17 Nov 2009 15:02:18 +0000";
            summary = ""Believe" is a Grammy Award winning global number one, Multi-Platinum Dance Song which served as the world-wide lead single for American singer Cher's twenty-third studio album Believe. It is noted for its use of a peculiar sound effect on the singer's vocals, which is referred to as the Cher effect today.  "Believe" was written by a number of writers including Paul Barry, Matt Gray, Brian Higgins, Stuart McLellan, Timothy Powell, and Steven Torch.";
        };
    };
}

Jag vet att jag är lat nu men jag hoppas att någon gjort detta förut och snabbt kan berätta hur jag ska göra.

Något sånt här är inge bra?

NSDictionary *track = [lastfm objectForKey:@track];
NSDictionary *album = [track objectForKey:@album];
NSArray *images = [album objectForKey:@image];
NSDictionary *image = [images objectAtIndex:3];
NSString *imageUrl = [image objectForKey:@"#text"];

Där lastfm är ett NSDictionary.

#text verkar ligga i ett dictionary som ligger i en array (image, med tre andra bilder) som ligger i ett dictionary (album) som ligger i ett dictionary (track).

Edit: hade fel index, snyggade till koden.

Senast redigerat 2012-09-03 10:03

Tack! Tack! Tack! Jisses vad detta sparade mig tid.

Ursprungligen av Mattias Hedman:

Tack! Tack! Tack! Jisses vad detta sparade mig tid.

Kul att kunna va till nån nytta.

Jag ska väcka min egen tråd till liv igen.
Kan alltid hoppas på att jag får bra svar igen.

Att plocka ut URL med det som marcushedenstrom skrev funkar hur bra som helst men jag har ett annat problem nu.

När jag ska söka i LastFM och jag får ett namn på antingen låt eller artist som innehåller t.ex. ä.
Då får jag inga träffar.

NSString *testURLString = [NSString stringWithFormat:@"http://ws.audioscrobbler.com/2.0/?method=trac...", artist, song];

Det enda jag gör nu är att jag ersätter alla mellanslag till ett +-tecken.
Men skickar jag inte t.ex ted+gärdestad ja då kraschar allt.
Någon som har tips på hur jag kommer åt svenska artister?

  • Medlem
  • Göteborg
  • 2012-10-03 11:55

Testa att URL-encoda artist- och songsträngen. Testa alltså ungefär följande anrop:

http://ws.audioscrobbler.com/2.0/?method=trac...

Så klart gaimasa! Hur har jag lyckats missa denna självklara sak!

TACK!

URL enkoda i iOS är då inte det enklaste. Inte att få det rätt åtminstone.
Just nu kör jag med stringByAddingPrecentEscapesUsingEncodig och där väljer jag då UTF8. Detta funkar men den översätter till "fel" procenttecken.
Någon som vet vad jag ska göra?

1
Bevaka tråden