获取URL中参数

作者: 喵子G | 来源:发表于2017-10-10 14:08 被阅读388次
    #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
    

    相关文章

      网友评论

        本文标题:获取URL中参数

        本文链接:https://www.haomeiwen.com/subject/nzmvyxtx.html