swift - Alamofire 返回错误的编码

标签 swift encoding alamofire

我正在使用

Alamofire.request(.GET, "http://")
        .responseString { _, _, string, _ in
            println(string)
    }

进行获取请求。响应包含西里尔字符,在 responseString 中它们看起来像这样(右上角):

top right

我应该如何修复编码?

最佳答案

您可以将 NSUTF8StringEncoding 与 Alamofire 的 responseString 方法一起使用:

Alamofire.request(.GET, "http://my1test.ru/applejesus.php?task=getCategory&categoryNumber=1")
            .responseString(encoding: NSUTF8StringEncoding) { (request, response, string, error) -> Void in
                if let result = string {
                    println(result)
                }
        }

结果:

picture{http://ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png},title{Продукция Apple}

关于swift - Alamofire 返回错误的编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31733254/

相关文章:

ios - 调用 applicationWillEnterForeground 后重新启动应用程序

Swift:线程 0 崩溃,不确定要在崩溃日志中查找什么

mysql - 对 MySQL 使用 UTF-8

ios - Swift 4 - 使用 httpbody 的 Alamofire 发布请求

arrays - 自动完成发送数据ID

c# - 当使用可执行文件的完整路径,以管理员身份运行时,Windows 10 无法访问指定的设备、路径或文件

python - 如何在 Python 中编码 (utf8mb4)

ios - iOS Swift 3 Alamofire 4.0.0

ios - 从 Objective-C 迁移到 Swift : AFNetworking > Alamofire

ios - 如何将一个 View Controller 与不同的 Realm 类一起使用