0
我正在使用swift在Xcode 6中處理iOS應用程序。我對這門語言很陌生,說實話,我正在拿出我有的小發型。在Swift中解析JSON不起作用
我要看到我的API調用LastFM等下面的JSON結果usingb的NSLog時( 「%@」,allResults)
artist = {
bio = {
content = "\n Cher (born Cherilyn Sarkisian; May 20, 1946) is an Oscar - and Grammy- winning American singer and actress. A major figure for over five decades in the world of popular culture, she is often referred to as the Goddess of Pop for having first brought the sense of female autonomy and self-actualization into the entertainment industry. She is known for her distinctive contralto and for having worked extensively across media, as well as for continuously reinventing both her music and image, the latter of which has been known to induce controversy. \n\n <a href=\"http://www.last.fm/music/Cher\">Read more about Cher on Last.fm</a>.\n \n \nUser-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.\n ";
formationlist = {
formation = {
yearfrom = 1965;
yearto = "";
};
};
links = {
link = {
"#text" = "";
href = "http://www.last.fm/music/Cher/+wiki";
rel = original;
};
};
published = "Thu, 6 Mar 2014 11:40:46 +0000";
summary = "\n Cher (born Cherilyn Sarkisian; May 20, 1946) is an Oscar - and Grammy- winning American singer and actress. A major figure for over five decades in the world of popular culture, she is often referred to as the Goddess of Pop for having first brought the sense of female autonomy and self-actualization into the entertainment industry. She is known for her distinctive contralto and for having worked extensively across media, as well as for continuously reinventing both her music and image, the latter of which has been known to induce controversy. \n\n <a href=\"http://www.last.fm/music/Cher\">Read more about Cher on Last.fm</a>.\n \n ";
yearformed = 1965;
};
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/63186903.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/63186903.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/63186903.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/63186903.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/500/63186903/Cher.png";
size = mega;
}
);
mbid = "bfcc6d75-a6a5-4bc6-8282-47aec8531818";
name = Cher;
ontour = 1;
similar = {
artist = (
{
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/98934631.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/98934631.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/98934631.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/98934631.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/_/98934631/Madonna+M.png";
size = mega;
}
);
name = Madonna;
url = "http://www.last.fm/music/Madonna";
},
{
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/32340147.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/32340147.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/32340147.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/32340147.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/500/32340147/Sonny++Cher+sonnycherbw2.png";
size = mega;
}
);
name = "Sonny & Cher";
url = "http://www.last.fm/music/Sonny+&+Cher";
},
{
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/98367071.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/98367071.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/98367071.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/98367071.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/500/98367071/Kylie+Minogue+VOGUE+AU+PNG+HQ.png";
size = mega;
}
);
name = "Kylie Minogue";
url = "http://www.last.fm/music/Kylie+Minogue";
},
{
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/96074665.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/96074665.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/96074665.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/96074665.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/_/96074665/Cline+Dion.png";
size = mega;
}
);
name = "C\U00e9line Dion";
url = "http://www.last.fm/music/C%C3%A9line+Dion";
},
{
image = (
{
"#text" = "http://userserve-ak.last.fm/serve/34/97259211.png";
size = small;
},
{
"#text" = "http://userserve-ak.last.fm/serve/64/97259211.png";
size = medium;
},
{
"#text" = "http://userserve-ak.last.fm/serve/126/97259211.png";
size = large;
},
{
"#text" = "http://userserve-ak.last.fm/serve/252/97259211.png";
size = extralarge;
},
{
"#text" = "http://userserve-ak.last.fm/serve/500/97259211/RuPaul+PNG.png";
size = mega;
}
);
name = RuPaul;
url = "http://www.last.fm/music/RuPaul";
}
);
};
stats = {
listeners = 940507;
playcount = 11967702;
};
streamable = 0;
tags = {
tag = (
{
name = pop;
url = "http://www.last.fm/tag/pop";
},
{
name = "female vocalists";
url = "http://www.last.fm/tag/female%20vocalists";
},
{
name = 80s;
url = "http://www.last.fm/tag/80s";
},
{
name = dance;
url = "http://www.last.fm/tag/dance";
},
{
name = rock;
url = "http://www.last.fm/tag/rock";
}
);
};
url = "http://www.last.fm/music/Cher";
};
我有一個試過如下:
func didRecieveAPIRequest(results, NSDictionary) {
let results: NSArray = results["artist'] as NSArray
我得到一個EXC_BREAKPOINT拋出並崩潰。所以嘗試了字典路線,我可以看到數據。事實上,我可以得到這個名稱和生物,但我無法訪問特定的圖片網址。我認爲它與嵌套有關,但是在這個時候我感到很茫然,因爲它可以調用Itunes API。它可能是一個新秀的錯誤,但和幫助將不勝感激。
讓我知道是否需要更多信息,並且請只提供建設性答覆。
在此先感謝。
如果您的「內容」值的長度是不相關的,有關eliding怎麼了? – GoZoner 2014-12-13 18:23:03