我正在尝试在 youtube 上进行搜索。此代码适用于英文字符。但是当我尝试输入像 ö、ü、ş 这样的非英语字母时,返回 null。
NSString *kStrJsonURL = [NSString stringWithFormat:@"http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&cp=1&q=%@&key=API_KEY&format=5&alt=jsonc&callback=?", self.searchField.text];
NSURL *url = [NSURL URLWithString:kStrJsonURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id getJSON) {
_JSON = getJSON;
NSLog(@"%@", _JSON);
} failure:nil];
[operation start];
我试图像这样编码 url 但不起作用..
[self.searchField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]