Objective c 在IOS应用程序中实现LastFM API
我有一个IOS应用程序,我正在尝试实现LastFM API来搜索曲目名称,但是我不知道该怎么做。我下面的教程是以烂西红柿为例的,我做得很好。然而,当我尝试同样的LastFM时,它不起作用。有什么解决办法吗?我尝试使用的API链接是 下面是我的代码示例Objective c 在IOS应用程序中实现LastFM API,objective-c,web-services,Objective C,Web Services,我有一个IOS应用程序,我正在尝试实现LastFM API来搜索曲目名称,但是我不知道该怎么做。我下面的教程是以烂西红柿为例的,我做得很好。然而,当我尝试同样的LastFM时,它不起作用。有什么解决办法吗?我尝试使用的API链接是 下面是我的代码示例 #import "SongSearchService.h" @implementation SongSearchService @synthesize searchTerm; @synthesize delegate; @synthesize
#import "SongSearchService.h"
@implementation SongSearchService
@synthesize searchTerm;
@synthesize delegate;
@synthesize results;
-(void)main {
NSLog(@"Service has run");
NSString *api_key = @"f3f936c8534e7cad4fff55861704cbf0";
NSString *search_term = [searchTerm stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *url = [NSString stringWithFormat:@"http://ws.audioscrobbler.com/2.0/?method=track.search&track=Believe", api_key, search_term];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
if (responseData !=nil) {
NSError *error =nil;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions error:&error];
if (error) {
[delegate serviceFinished:self withError:YES];
} else {
results = (NSArray *) [json valueForKey:@"Songs"];
[delegate serviceFinished:self withError:NO];
}
} else {
[delegate serviceFinished:self withError:YES];
}
}
@end
到底是什么问题?响应数据总是零吗?如果没有,您从服务器得到了什么?尝试使用以下内容进行日志记录:
NSLog(@“responseData:%@,[[NSString alloc]initWithData:responseData])代码>确切的问题是,当我运行应用程序并搜索歌曲时,它返回为未找到任何结果。它是否返回空的“歌曲
”数组,或者它遇到了代码中的两个错误条件之一?它不返回任何内容,代码中也没有弹出错误。“服务已运行”显示在日志中?