我有一个NSURL:serverCall?x = a&y = b&z = c获取y值的最快,最有效的方法是什么?谢谢
3 回答
忽然笑
TA贡献1806条经验 获得超5个赞
我很确定您必须自己解析它。但是,还算不错:
NSString * q = [myURL query];
NSArray * pairs = [q componentsSeparatedByString:@"&"];
NSMutableDictionary * kvPairs = [NSMutableDictionary dictionary];
for (NSString * pair in pairs) {
NSArray * bits = [pair componentsSeparatedByString:@"="];
NSString * key = [[bits objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString * value = [[bits objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[kvPairs setObject:value forKey:key];
}
NSLog(@"y = %@", [kvPairs objectForKey:@"y"]);
- 3 回答
- 0 关注
- 524 浏览
添加回答
举报
0/150
提交
取消