您的当前位置:首页正文

获取URL中参数

来源:华拓网
#import "NSString+URLComponents.h"

@implementation NSString (URLComponents)

- (NSDictionary *)jkr_urlStringGetURLComponents {
    if (self == nil || self.length == 0) return nil;
    NSURLComponents *urlComponents = [NSURLComponents componentsWithString:self];
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    NSArray *queryItems = urlComponents.queryItems;
    for (NSURLQueryItem *item in queryItems) {
        if (item.name && item.value) {
            [dictionary setObject:item.value forKey:item.name];
        }
    }
    return dictionary;
}

@end