0

ユーチューブで検索してみました。このコードは、英語の文字で正常に機能します。しかし、ö、ü、ş などの英語以外の文字を入力しようとすると、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]
4

2 に答える 2

0

URLEncoding を試しましたkStrJsonURLか? この投稿の受け入れられた回答を参照してください。

文字列を URL エンコードする方法

于 2013-10-29T15:58:59.383 に答える