NSURL为参数字符串中的键提取单个值

我有一个NSURL:

serverCall?x = a&y = b&z = c

获取y值的最快,最有效的方法是什么?

谢谢


拉莫斯之舞
浏览 525回答 3
3回答

忽然笑

我很确定您必须自己解析它。但是,还算不错: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"]);
打开App,查看更多内容
随时随地看视频慕课网APP