Get the first Element of a Dictionary:
[gist https://gist.github.com/80552a75bfdf071f58cb /]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { | |
NSLog(@"url recieved: %@", url); | |
NSLog(@"query string: %@", [url query]); | |
NSLog(@"host: %@", [url host]); | |
NSLog(@"url path: %@", [url path]); | |
NSDictionary *dict = [self parseQueryString:[url query]]; | |
NSLog(@"query dict: %@", dict); | |
return YES; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.idev101.com/code/Objective-C/custom_url_schemes.html | |
- (NSDictionary *)parseQueryString:(NSString *)query { | |
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithCapacity:6] autorelease]; | |
NSArray *pairs = [query componentsSeparatedByString:@"&"]; | |
for (NSString *pair in pairs) { | |
NSArray *elements = [pair componentsSeparatedByString:@"="]; | |
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
[dict setObject:val forKey:key]; | |
} | |
return dict; | |
} |
URL: http://gdata.youtube.com/feeds/api/users/unpluggedacoustic1/uploads/?alt=json
JSON:
"media$group":{
"media$thumbnail": [
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/0.jpg","height":360,"width":480,"time":"00:01:39.500" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/1.jpg","height":90,"width":120,"time":"00:00:49.750" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/2.jpg","height":90,"width":120,"time":"00:01:39.500" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/3.jpg","height":90,"width":120,"time":"00:02:29.250" }
]
}
NSDictionary *mediagroup = [entry objectForKey:@"media$group"];
//NSLog(@"MediaGroup: %@", mediagroup);
NSDictionary *mediathumbnail = [mediagroup objectForKey:@"media$thumbnail"][0];
NSString *url = [mediathumbnail objectForKey:@"url"];
NSLog(@"%@", url);