Alamofire返回错误的编码

编程入门 行业动态 更新时间:2024-10-20 11:43:08
本文介绍了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返回错误的编码

本文发布于:2023-11-26 06:54:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!