1
henryshen233 OP - (IBAction)searchButton:(id)sender {
NSString *searchContent = _searchWord.stringValue; NSString *urlStr = [[NSString alloc] initWithFormat:@"http://dict-co.iciba.com/api/dictionary.php?w=%@&type=json&key=*********************", searchContent]; NSURL *url = [[NSURL alloc] initWithString:urlStr]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"GET"; request.timeoutInterval = 60; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; NSString *wordName = [dict valueForKey:@"word_name"]; _searchResult.stringValue = wordName; }]; [task resume]; } |
2
henryshen233 OP 请教各位朋友,希望有朋友能够抽出宝贵时间看一眼,谢谢
|