ios - Xcode 将特殊字符(NSString)转换为 NSData

标签 ios xcode special-characters nsdata

<分区>

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/

上一篇:iphone - UIImageView autoresizingMask 行为

下一篇:objective-c - NSUSerDefaults 与 NSMutableArray 按 desc 顺序排序

相关文章:

ios - 当我们使用 Storyboard 时,如何在 Objective-C 中实现自定义 init 方法?

ios - iPhone 6/6plus 中 SKScene 中的标签未完全对齐

C# 去除特殊字符

iphone - UINavigationcontroller 的背景图片

ios - iOS 11.1.2 上的 Xamarin.Forms : Webview loads a bigger font

php - 来自温度值的 UIColor

iphone - UIWindow 和 UIView 之间的区别

ios - 获取第一个日期,最后一个日期?

ruby-on-rails - REST 客户端和外来字符

python - 如何从 python 中的元素列表中删除特殊字符?