解决方法
你必须使用这种格式:
https://api.soundcloud.com/me/tracks?q=SEARCHTEXT\u0026amp;format=json
请记住,如果用户输入空格,您必须更换它,您可以实现此目的
NSString * search = [originalSearch stringByReplacingOccurrencesOfString:@“”withString:@“”];
然后,只需要像这样请求JSON数据:
[SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json",search]] usingParameters:nil withAccount:[SCSoundCloud account] sendingProgressHandler:nil responseHandler:^(NSURLResponse *response,NSData *data,NSError *error) {
我的最终代码如下所示:
NSString *search = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; [SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json",NSError *error) { NSError *jsonError; NSJSONSerialization *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; if (!jsonError && [jsonResponse isKindOfClass:[NSArray class]]) { self.searchQuery = (NSArray *)jsonResponse; [self.tableView reloadData]; } else { NSLog(@"%@",error.localizedDescription); } }];`
我希望这有帮助!