如何在iOS中进行URL解码 - 目标C. [英] How to URL Decode in iOS - Objective C

查看:119
本文介绍了如何在iOS中进行URL解码 - 目标C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stringByReplacingPercentEscapesUsingEncoding方法无法正常工作,因为它不解码不以%字符开头的特殊符号,即+字符。有谁知道在iOS中更好的方法吗?

The stringByReplacingPercentEscapesUsingEncoding method is not working properly as it's not decoding special symbols that dont start with a % character, i.e., the + character. Does anyone know of a better method to do this in iOS?

以下是我目前正在使用的内容:

Here's what I'm currently using:

NSString *path = [@"path+with+spaces"
     stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

以下是输出的示例:

path + with + spaces

path+with+spaces

推荐答案

NSString *path = [[@"path+with+spaces"
    stringByReplacingOccurrencesOfString:@"+" withString:@" "]
    stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

请注意,空间加号替换仅用于应用程序/ x-www-form-urlencoded data - URL的查询字符串部分,或 POST 请求的正文。

Note that the plus-for-space substitution is only used in application/x-www-form-urlencoded data - the query string part of a URL, or the body of a POST request.

这篇关于如何在iOS中进行URL解码 - 目标C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆