Skip to content

Instantly share code, notes, and snippets.

@r3econ
Created April 1, 2014 21:12

Revisions

  1. Rafał Sroka created this gist Apr 1, 2014.
    32 changes: 32 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // Create a sample URL.
    NSURL *url = [NSURL URLWithString:@"http://www.bbc.co.uk/tv/programmes/genres/drama/scifiandfantasy/schedules/upcoming.json"];

    // Create a download task.
    NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:url
    completionHandler:^(NSData *data,
    NSURLResponse *response,
    NSError *error)
    {
    if (!error)
    {
    NSError *JSONError = nil;

    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data
    options:0
    error:&JSONError];
    if (JSONError)
    {
    NSLog(@"Serialization error: %@", JSONError.localizedDescription);
    }
    else
    {
    NSLog(@"Response: %@", dictionary);
    }
    }
    else
    {
    NSLog(@"Error: %@", error.localizedDescription);
    }
    }];
    // Start the task.
    [task resume];