iOS开发技术分享

获取URL中参数

2017-10-10  本文已影响388人  喵子G
#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
上一篇 下一篇

猜你喜欢

热点阅读