Skip to content

Instantly share code, notes, and snippets.

@kkdai
Forked from yyjim/gist:0b13e823646921827220
Created December 4, 2015 00:40
Show Gist options
  • Save kkdai/f6ee743172f6c2ca67e4 to your computer and use it in GitHub Desktop.
Save kkdai/f6ee743172f6c2ca67e4 to your computer and use it in GitHub Desktop.
taipei opendata test
NSURL *url = [NSURL URLWithString:@"http://opendata.dot.taipei.gov.tw/opendata/alldescriptions.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
unsigned long big5 = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5_HKSCS_1999);
NSString *json = [[NSString alloc] initWithData:data encoding:big5];
NSError *error;
NSDictionary *dictionary =
[NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions
error:&error];
NSLog(@"dict %@", dictionary);
}];
@kkdai
Copy link
Author

kkdai commented Dec 4, 2015

可以解決iOS 連接JSON的編碼問題..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment