本文介绍了Alamofire返回错误的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用
Alamofire.request(.GET,my1test.ru/applejesus.php ?task = getCategory& categoryNumber = 1) .responseString {_,_,string,_ in println(string)} / pre>来获取请求。响应包含了系数符号,在响应中它们看起来像这样(右上角):
如何修复编码?
解决方案可以使用 NSUTF8StringEncoding 与Alamofire的 responseString 方法:
Alamofire.request (.GET,my1test.ru/applejesus.php?task=getCategory&categoryNumber=1) .responseString(encoding:NSUTF8StringEncoding){(request,response,string,error) - >如果let = string { println(result)} }结果:
图片{ ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png },标题{ПродукцияApple}
I`m using
Alamofire.request(.GET, "my1test.ru/applejesus.php?task=getCategory&categoryNumber=1") .responseString { _, _, string, _ in println(string) }to make get-request. Response contains сyrillic symbols and in responseString they looks like this (top-right):
How should I fix encoding?
解决方案You can use NSUTF8StringEncoding with Alamofire's responseString method:
Alamofire.request(.GET, "my1test.ru/applejesus.php?task=getCategory&categoryNumber=1") .responseString(encoding: NSUTF8StringEncoding) { (request, response, string, error) -> Void in if let result = string { println(result) } }Result:
picture{ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png},title{Продукция Apple}
更多推荐
Alamofire返回错误的编码
发布评论