저는 JavaScript와 jQuery에 다소 익숙하지만, 제가 만드는 동안 배우고 있습니다. JS (https://github.com/fxb/javascript-last.fm-api)의 last.fm API를 사용하고 있으며 내 목록의 첫 번째 앨범을 가져 오려고합니다.배열의 첫 번째 값 얻기
나는 다음과 같은 코드를 사용하여 데이터를 가져 :
lastfm.track.getInfo({track: activeMedia.title, artist: activeMedia.author}, {success: function(trackInfoResult){
// doing things with trackInfoResult
}, error: function(code, message){
console.log("Error code: " + code);
}});
이의 출력은 다음과 같은 구조 (http://www.last.fm/api/show/track.getInfo에 있음)된다
<track>
<id>1019817</id>
<name>Believe</name>
<mbid/>
<url>http://www.last.fm/music/Cher/_/Believe</url>
<duration>240000</duration>
<streamable fulltrack="1">1</streamable>
<listeners>69572</listeners>
<playcount>281445</playcount>
<artist>
<name>Cher</name>
<mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid>
<url>http://www.last.fm/music/Cher</url>
</artist>
<album position="1">
<artist>Cher</artist>
<title>Believe</title>
<mbid>61bf0388-b8a9-48f4-81d1-7eb02706dfb0</mbid>
<url>http://www.last.fm/music/Cher/Believe</url>
<image size="small">http://userserve-ak.last.fm/serve/34/8674593.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/8674593.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/8674593.jpg</image>
</album>
<toptags>
<tag>
<name>pop</name>
<url>http://www.last.fm/tag/pop</url>
</tag>
...
</toptags>
<wiki>
<published>Sun, 27 Jul 2008 15:44:58 +0000</published>
<summary>...</summary>
<content>...</content>
</wiki>
</track>
내 아티스트 이름을 얻기 및 ID 내가 할 수있는 다음 코드로 관리 :
console.log(rackInfoResult.track.name);
하지만 이제 첫 번째 앨범을 갖고 싶습니다. position = "1"인 앨범을 어떻게 선택합니까?
당신이'rackInfoResult.track.album'을 시도 했 trackInfoResult.track 뒤에 키 중 하나를 추가를 추적하려면 다음 코드를 사용? – adeneo
음, 그게 나에게 [object Object] 결과로 – Kiwi