iOS URL参数转字典

2022-10-20  本文已影响0人  anny_4243
+(NSDictionary *) parameterWithURL:(NSURL *) url {    
    NSMutableDictionary *parm = [[NSMutableDictionary alloc]init];  
    //传入url创建url组件类
    NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:url.absoluteString];
    //回调遍历所有参数,添加入字典
    [urlComponents.queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [parm setObject:obj.value forKey:obj.name];
    }];  
    return parm;   
}
上一篇 下一篇

猜你喜欢

热点阅读