最佳途径把url参数转换为字符串值

在iphong中把url分割为数值,我的计划是这样:

appname://user=jonsmith&message=blah%20blah

这样我可以将user和message作为两个NSString接收。有没有更好的方法?谢谢

假设你的URL是名为url的NSURL

NSMutableDictionary *queryParams = [[NSMutableDictionary alloc] init];
NSArray *components = [[url query] componentsSeparatedByString:@"&"];

for (NSString *component in components) {
    NSArray *pair = [component componentsSeparatedByString:@"="];

    [queryParams setObject:[[pair objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding]
                    forKey:[pair objectAtIndex:0]]; 
}

...

[queryParams release];