Alamofire返回错误的编码 [英] Alamofire returns wrong encoding
本文介绍了Alamofire返回错误的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用
Alamofire.request(.GET,http://my1test.ru/applejesus.php ?task = getCategory& categoryNumber = 1)
/ pre>
.responseString {_,_,string,_ in
println(string)
}
来获取请求。响应包含了系数符号,在响应中它们看起来像这样(右上角):
如何修复编码?
解决方案可以使用
NSUTF8StringEncoding
与Alamofire的
responseString
方法:Alamofire.request (.GET,http://my1test.ru/applejesus.php?task=getCategory&categoryNumber=1)
.responseString(encoding:NSUTF8StringEncoding){(request,response,string,error) - >如果let = string {
println(result)
}
}
结果:
图片{ http://ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png },标题{ПродукцияApple}
I`m using
Alamofire.request(.GET, "http://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'sresponseString
method: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) } }
Result:
picture{http://ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png},title{Продукция Apple}
这篇关于Alamofire返回错误的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文