<分区>
<分区>
Possible Duplicate:
How to prepare an NSURL from an NSString continaing international characters?
我在将特殊字符转换为 NSData 格式时遇到问题。
NSString *strURL = [NSString stringWithFormat:@"http://www.???.com/1.php?test=你好"];
NSLog(@"%@", strURL);
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSLog(@"%@", dataURL);
当我打印出 dataURL 时,结果为 (null),而当我的 strURL 为英文时,它将打印出应该打印的正确数据。
请指教。
最佳答案
您应该尝试将 UTF-8 添加到字符串中
[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
关于ios - Xcode 将特殊字符(NSString)转换为 NSData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14089964/