- (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];
}