URL 转化为 Dictionary 字典

通过网上查找,参考了别人的知识,(不算偷知道,我自己也亲手做了)我知道自己还有很多不足之处,希望有一天能够站在金字塔尖

url  为:

woaiwodejiaxiang://cn.jiaxiang.ZG/loader?dt=1254896584562&cityId=tr&deviceNumber=13185058252&userId=20985532&roleType=2&state=1&token=dad8fa595beda8306ea1aa01250aeb0&deviceIMEI=3951545154614522

1.

NSString *urlString = [NSString stringWithFormat:@"%@",url];// 将URL转化为nsstring

NSMutableArray *urlArray =[NSMutableArray arrayWithObject:urlString];// 并放在数组中

NSRange range = [urlArray[0] rangeOfString:@"?"]; // 获取问号的位置 问号后面是参数列表   urlArray[0] :我只有一个元素在数组中

NSString *propertys = [urlArray[0] substringFromIndex:(int)range.location]; 参数列表

NSArray *subArray =[propertys componentsSeparatedByString:@"&"]; // 进行字符串的拆分,通过&来拆分,

2.

NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithCapacity:8];// 8 是 我的URL中有8个参数 最总得到的字典有8个键值对

for (int j = 0; j<subArray.count; j++) {

NSArray *dicArray = [subArray[j] componentsSeparatedByString:@"="]; // 等号“=” 是用来分割键值对

[tempDic setObject:dicArray[1] forKey:dicArray[0]];// 给字典添加键值对关系,(我参考别人的)

}

NSLog(@"打印参数列表生成的字典:\n%@", tempDic);// 输出转化的字典

{
"?dt" = 1254896584562;
cityId = gy;
deviceIMEI = 3951545154614522;
deviceNumber = 13185058252;
roleType = 1;
state = 1;
token = dad8fa595beda8306ea1aa01250aeb0;
userId = 20985532;
}

时间: 2024-08-26 17:00:12

URL 转化为 Dictionary 字典的相关文章

dictionary(字典)

dictionary(字典):   字典对象   字典是一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 1.      dic={"name":"sang","age":22,"hobby":"game"}             $字典有2大特点:*(1)无序,(2)key键唯一 print(dic) 2.       dictionary的创建  

C#的Dictionary字典

Dictionary Dictionary可以取代Hashtable了; 有一种新的遍历方式 foreach(KeyValuePair <int,string> kv in dic){} dictionary练习 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Dictionary字典 { c

上传程序Dictionary 字典 哈希--多读一写锁ReaderWriterLock

//上传程序Dictionary 字典 哈希 /// <summary> /// 车辆控制信息哈斯表,Key是终端号,Value是车辆信息控制对象 /// </summary> private Dictionary<string, MsgObject> _MsgObjectHashMap = new Dictionary<string, MsgObject>(); public Dictionary<string, MsgObject> MsgO

VBS使用Scripting.Dictionary字典对象

VBS使用Scripting.Dictionary字典对象 标题: VBS使用Scripting.Dictionary字典对象作者: Demon链接: http://demon.tw/copy-paste/vbs-scripting-dictionary-object.html版权: 本博客的所有文章,都遵守"署名-非商业性使用-相同方式共享 2.5 中国大陆"协议条款. Scripting.Dictionary是个很有用的组件,其创建了类似于Key索引对应Value值的字典对象,并且

C#中的Dictionary字典类介绍

关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionary.html 说明    必须包含名空间System.Collection.Generic     Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)     键必须是唯一的,而值不需要唯一的     键和值都可以是任何类型(比如:string, int, 自定义类型,等等

C# Json数据反序列化为Dictionary并根据关键字获取指定值1

Json数据: { "dataSet": { "header": { "returnCode": "0", "errorInfo": "HTTP请求错误", "version": "V1.0R010", "totalRows": "2000", "returnRows": "20

你能熟练使用Dictionary字典和List列表吗?(转)

命名空间System.Collections.Generic中有两个非常重要,而且常用的泛型集合类,它们分别是Dictionary<TKey,TValue>字典和List<T>列表.Dictionary字典通常用于保存键/值对的数据,而List列表通中用于保存可通过索引访问的对象的强类型列表.下面来总结一下,用代码来演示怎么初始化,增加,修改,删除和遍历元素. Dictionary<TKey,TValue>字典 代码如下: namespace DictionaryDem

.Net学习笔记----2015-06-25(File类的读写文件、List泛型集合、装箱和拆箱、Dictionary字典集合)

File类:静态类,Create Delete Copy Move ,主要用来对数据对文本文件进行读写 File类:缺点:只能读写小文件 读写操作: //byte[] buffer = File.ReadAllBytes(@"C:\Users\Administrator\Desktop\new.txt"); ////将字节数组中的每一个元素都要按照我们指定的编码各式解码成字符串 ////UTF-8 GB2312 GBK ASCII Unicode //string s = Encodi

C# Json数据反序列化为Dictionary并根据关键字获取指定值

Json数据: { "dataSet": { "header": { "returnCode": "0", "errorInfo": "HTTP请求错误", "version": "V1.0R010", "totalRows": "2000", "returnRows": "20