1>诸如 (lldb) po bannerModel.linkUrl
sourceId=1641&type=course 除了字符串切割 还有办法取出来sourceId的值和type的值吗?
+ (NSDictionary *)getQueryStringPara:(NSString *)queryStr {
if (queryStr.length <= 0) {
return nil;
}
queryStr = [self URLDecodedString:queryStr];
NSArray <NSString *> *para = [queryStr componentsSeparatedByString:@"&"];
NSMutableDictionary *dict_M = [NSMutableDictionary dictionary];
for (NSString * com in para) {
NSArray <NSString *> *arr = [com componentsSeparatedByString:@"="];
[dict_M setObject:arr[1] forKey:arr[0]];
}
return dict_M.copy;
}
+ (NSString *)URLDecodedString:(NSString *)str
{
NSString *decodedString=(__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)str, CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
return decodedString;
}
如果是完整的url 可以考虑// NSURLComponents *urlComponents = [NSURLComponents componentsWithString:readerScanResult];
// NSArray *items = urlComponents.queryItems;
// NSString *examID = nil;
// for (NSURLQueryItem *item in items) {
// if ([item.name isEqual:@"id"]) {
// examID = item.value;
// }
// }
打印urlComponents 根据各个参数取值