@implementation NSString (URLParser)
-(NSDictionary*)parserToDict
{
NSScanner *scanner = [NSScanner scannerWithString:self];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?="]];
NSString *key;
NSString *value;
NSMutableArray *keys = [NSMutableArray new];
NSMutableArray *vars = [NSMutableArray new];
[scanner scanUpToString:@"?" intoString:nil]; //ignore the beginning of the string and skip to the vars
while ([scanner scanUpToString:@"=" intoString:&key]&&[scanner scanUpToString:@"&" intoString:&value]) {
//[vars addObject:[tempString copy]];
[keys addObject:key];
[vars addObject:value];
}
return [NSDictionary dictionaryWithObjects:vars forKeys:keys];
}
@end
时间: 2024-10-09 06:20:09