码迷,mamicode.com
首页 > 移动开发 > 详细

[iOS]URL编码和解码

时间:2016-03-03 22:46:41      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:

1. 首先来看下什么样的是URL编码(字符串中带有%22 类似这样的)

NSString *str = @"http://m.tuniu.com/api/home/data/index/c/%7B%22v%22%3A%227.1.0%22%2C%22ct%22%3A20%2C%22dt%22%3A1%2C%22p%22%3A11210%2C%22cc%22%3A2500%7D/d/%7B%22clientModel%22%3A%22HONOR+H30-L01%22%2C%22width%22%3A720%7D"

把URL解码

// 解码

  NSString *str2 = [str stringByRemovingPercentEncoding];  (iOS9.0(包括9.0)以上使用)

  NSString *str2 = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  (iOS9.0以下使用)

把URL编码

// 编码

  NSString *str3 = [str2 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]]; (iOS9.0(包括9.0)以上使用)

  NSString *str3 = [str2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  (iOS9.0以下使用)

[iOS]URL编码和解码

标签:

原文地址:http://www.cnblogs.com/wangqi1221/p/5240237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!