在我的ios应用程序中,我使用json与我的网络服务器进行通信。当我在我的应用程序中使用特殊字符作为æøå的帖子时,数据库中的结果是âåå。当我直接在数据库中发帖并获取结果时,它可以正常工作。在我的Android应用程序中,使用json都可以正常工作。我希望你能帮助我 - 代码在这里:
//////NSsession
NSString *noteDataString = [NSString stringWithFormat:@"text=%@&rating=%@&tag=%@&barcode=%@&userid=%@",reviewTxt,[self.ratingBar getRatings] ,@"addReview", barcode,uid];
NSString *noteDateStringEncode = [noteDataString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfiguration.HTTPAdditionalHeaders = @{
@"api-key" : @"API_KEY"
};
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURL *url = [NSURL URLWithString:getDataURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPBody = [noteDateStringEncode dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *jsonData = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
NSInteger success = 0;
success = [jsonData[@"success"] integerValue];
NSLog(@"Success: %ld",(long)success);
if(success == 1)
{
NSLog(@"Add review SUCCESS");
[self performSegueWithIdentifier:@"reviewComplete" sender:self];
} else {
NSString *error_msg = (NSString *) jsonData[@"error_message"];
[self alertStatus:error_msg :@"Add review Failed!" :0];
}
}];
[postDataTask resume];