1

我正在尝试使用必应搜索 API 进行图像搜索,但它不适用于 unicode 字符

NSDictionary *bingParams = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"'image'", @"Sources",
                            [NSString stringWithFormat:@"'%@'",[[searchBar text] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]], @"Query",
                            @"'Size:Medium'", @"ImageFilters",
                            @"json", @"$format",
                            @"50", @"$top",
                            nil];
NSLog(@"%@",[bingParams objectForKey:@"Query"]);

if (!_httpClient) {
    _httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.datamarket.azure.com"]];
    [_httpClient clearAuthorizationHeader];
    [_httpClient setParameterEncoding:AFJSONParameterEncoding];
    [_httpClient setAuthorizationHeaderWithUsername:BING_SEARCH_KEY password:BING_SEARCH_KEY];
}

NSMutableURLRequest *searchRequest = [_httpClient requestWithMethod:@"GET" path:@"/Bing/Search/v1/Composite" parameters:bingParams];
[searchRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[searchRequest setTimeoutInterval:30.0];
AFJSONRequestOperation *searchOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:searchRequest
                                                                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                                                                                            NSLog(@"%@",JSON);    
                                                                                        }
                                                                                        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
                                                                                            NSLog(@"%@",[error localizedDescription]);
                                                                                        }];
[_httpClient enqueueHTTPRequestOperation:searchOperation];

第一个 NSLog 打印以下内容:

`%E6%97%A5`

第二个 NSLog 打印很长,但有一个键值对我想突出显示

"__metadata" =                 {
  type = ExpandableSearchResult;
  uri = "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?ImageFilters='Size:Medium'&Query='\U65e5'&Sources='image'&$skip=0&$top=1";
};

注意Query='\U65e5',这不同于'%E6%97%A5'

我想知道我做错了什么?或者这是我无法控制的搜索 API 的问题?

4

0 回答 0