解析NSURL查询属性 [英] Parse NSURL query property
本文介绍了解析NSURL查询属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网址如 myApp:// action / 1?parameter = 2& secondparameter = 3
使用属性查询,我得到以下部分 URL
With the property query I get following part of my URL
parameter=2&secondparameter=3
有什么方法可以很容易地把它放在 NSDictionary
或数组
?
Is there any way easy to put this in a NSDictionary
or an Array
?
很多
推荐答案
类似的东西:
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *param in [url componentsSeparatedByString:@"&"]) {
NSArray *elts = [param componentsSeparatedByString:@"="];
if([elts count] < 2) continue;
[params setObject:[elts lastObject] forKey:[elts firstObject]];
}
注意:这是示例代码。不管理所有错误情况。
Note : This is sample code. All error cases are not managed.
这篇关于解析NSURL查询属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文