我正在使用 Houndify SDK 的 v1.05 及其演示应用程序。我正在对音乐进行语音搜索,并努力了解如何从 Houndify 响应中提取 Spotify 曲目 ID。
Houndify 用一个对象进行响应,HoundDataHoundServer
他们的示例显示了对它的处理,如下所示:
HoundDataCommandResult* commandResult = response.allResults.firstObject;
self.responseTextView.text = commandResult.writtenResponse;
它继续像这样转储整个响应:
NSDictionary* nativeData = commandResult[@"NativeData"];
NSLog(@"NativeData: %@", nativeData);
在一个示例转储中,它从 NSLog 中显示了这一点:
NativeData: {
EntitySpecificationType = Explicit;
MusicCommandNativeDataKind = MusicSearchCommandNativeData;
OrderToDisplay = (
Track,
Artist,
Album
);
SearchParameters = {
MusicSearchTargetType = "MUSIC_SEARCH_TARGET_TYPE_TOP";
SearchCriteriaType = SearchForTracks;
};
Tracks = (
{
AlbumDate = "2009-11-20";
AlbumID = 300117215516977013;
AlbumName = "The Fame Monster";
ArtistID = 200346971627324820;
ArtistName = "Lady Gaga, Beyonc\U00e9";
AudioPreviewURL = "http://www.amazon.com/gp/dmusic/aws/sampleTrack.html?clientid=SoundHound&ASIN=B002X07TMC";
AutoPlayPreview = 1;
BuyLinks = (
{
Store = PlayStore;
URL = "https://play.google.com/store/music/album?id=B5t7w66ic4dqvfzfg3lse6v7ncy&tid=song-Tr6zlzmvtxg3bnfhlgyeglwgr24&PAffiliateID=111l3po";
},
{
Store = ITunes;
URL = "https://itunes.apple.com/us/album/telephone-feat.-beyonce-passion/id382900899?i=382901246&uo=4&at=10lIs&ct=t-100236021077260375_62000USd";
}
);
LyricsURL = "http://www.google.com/m?q=lyrics+Telephone+Lady+Gaga";
MusicThirdPartyIds = (
{
DeepLinks = (
"spotify:track:1IaYWv32nFFMdljBIjMY5T"
);
Ids = (
"spotify:track:1IaYWv32nFFMdljBIjMY5T"
);
MusicThirdParty = {
Name = Spotify;
};
},
{
DeepLinks = (
"https://itunes.apple.com/us/album/telephone-feat.-beyonce-passion/id382900899?i=382901246&uo=4&at=10lIs&ct=listen_on_apple_music&app=music"
);
Ids = (
382901246
);
MusicThirdParty = {
Name = AppleMusic;
};
},
{
DeepLinks = (
);
Ids = (
382901246,
52725806,
25273502
);
MusicThirdParty = {
Name = Default;
};
},
{
DeepLinks = (
"pandorav2:/createStation?artist=Lady+Gaga&song=Telephone&type=artist&partnerCode=2&trackingCode=x-009427-0035-1149&adId="
);
Ids = (
);
MusicThirdParty = {
Name = Pandora;
};
}
);
PreviewLinks = (
{
Source = itunes;
Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
},
{
Source = itunes;
Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
},
{
Source = itunes;
Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
}
);
TrackID = 100236021077260375;
TrackName = Telephone;
}
);
UserRequestedAutoPlay = 1;
}
2016-05-27 12:42:24.604 HoundifySDK Test Application[5834:2094266] {
DeepLinks = (
"spotify:track:1IaYWv32nFFMdljBIjMY5T"
);
Ids = (
"spotify:track:1IaYWv32nFFMdljBIjMY5T"
);
MusicThirdParty = {
Name = Spotify;
};
}
我试过用这个访问Spotify ID:
NSDictionary *test = commandResult[@"NativeData"][@"Tracks"][0][@"MusicThirdPartyIds"][0];
但是,尽管当我尝试使用上面的测试变量提取 SpotifyID 时,NSLog 在“Tracks”下显示了 SpotifyID 的键和值,但 SpotifyID 的键报告如下(在 xcode 中):
test __NSDictionaryM * 3 key/value pairs 0x000000013d5aa910
[0] = (no summary) : @"1 element"
[1] @"MusicThirdParty" : 1 key/value pair
[2] (no summary) : @"1 element"
所以我想要的关键是“没有总结”:
[2] (null) (no summary) : @"1 element"
key NSTaggedPointerString * 0xa000000007364493
value __NSArrayM * @"1 element" 0x000000013d5aaca0
[0] __NSCFString * @"spotify:track:1IaYWv32nFFMdljBIjMY5T" 0x000000013d5aad50
我显然误解了我应该如何访问数据。有人可以请教吗?谢谢。