Reputation: 857
I am trying to an image search with the Bing Search API but it doesn't work well with unicode characters
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];
the first NSLog prints the following:
`%E6%97%A5`
The second NSLog prints very long, but there is a key-value pair I want to highlight
"__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";
};
Note Query='\U65e5'
, which is different from '%E6%97%A5'
I am wondering what I am doing wrong? or is this a problem with the search API which is out of my control?
Upvotes: 1
Views: 268