Created
April 11, 2013 07:04
-
-
Save ninjinkun/5361327 to your computer and use it in GitHub Desktop.
ObjC ugomemo sample
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
id apiRequest(NSString *url) | |
{ | |
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; | |
NSHTTPURLResponse *res; | |
NSError *error; | |
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&error]; | |
if (error) { | |
return nil; | |
} | |
NSError *jsonError; | |
return [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSDictionary *user = apiRequest(@"http://ugomemo.hatena.ne.jp/[email protected]"); | |
NSDictionary *movies = apiRequest(@"http://ugomemo.hatena.ne.jp/11F9E990AA34FFBC@DSi/movies.json"); | |
NSLog(@"%@さんは%@個の作品を投稿しています。\n", user[@"name"], movies[@"count"]); | |
//-> ピョコライフさんは31個の作品を投稿しています。 | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment