I am refering this answer to parse url but when parse this url
NSString *urlString = @"https://www.example.com/product-detail?journey_id=123456&iswa=1";
I am getting my 1st key is https://www.example.com/product-detail?journey_id
But I need only journey_id
as my key.
This is what I have done in coding:
NSString *urlString = @"https://www.example.com/product-detail?journey_id=123456&iswa=1";
NSMutableDictionary *waLoginDictionary = [[NSMutableDictionary alloc] init];
NSArray *urlComponents = [urlString componentsSeparatedByString:@"&"];
for (NSString *keyValuePair in urlComponents) {
NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];
NSString *key = [[pairComponents firstObject] stringByRemovingPercentEncoding];
NSString *value = [[pairComponents lastObject] stringByRemovingPercentEncoding];
[waLoginDictionary setObject:value forKey:key];
}
NSLog(@"%@", waLoginDictionary);
I am getting This output:
{
"https://www.example.com/product-detail?journey_id" = 123456;
iswa = 1;
}