iOS utf-8全编码问题

  • (NSString )stringByAddingPercentEscapesUsingEncodingExt:(NSStringEncoding)enc stringWith:(NSString )str
    {
    if([str respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)] == YES)
    {
    NSCharacterSet
    set = [[NSCharacterSet characterSetWithCharactersInString:@"!
    '();:@&=+$,/?%#[]"] invertedSet];
    return [str stringByAddingPercentEncodingWithAllowedCharacters:set];
    }
    else
    {

pragma clang diagnostic push

pragma clang diagnostic ignored "-Wdeprecated-declarations"

// NSString * newString = (__bridge_transfer NSString *)
NSString * newString = ( NSString )
CFURLCreateStringByAddingPercentEscapes(NULL,
(__bridge CFStringRef)str,
NULL,
(CFStringRef)@"!
'();:@&=+$,/?%#[]",
CFStringConvertNSStringEncodingToEncoding(enc));

pragma clang diagnostic pop

    return newString;
}

}

调用
content = [self stringByAddingPercentEscapesUsingEncodingExt:NSUTF8StringEncoding stringWith:content];

你可能感兴趣的:(iOS utf-8全编码问题)