Skip to content

Response Parsing, Error Handling 1

Alfie Hanssen edited this page Nov 22, 2013 · 2 revisions

Convert the below pseudo-code into objc. Check out the following class references for help:

NSJSONSerialization

NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        
    // Convert this pseudo-code into objc:
        
    if error, print it
    else 
        convert data into an NSDictionary using the NSJSONSerialization class's method JSONObjectWithData:options:error:

        if JSON conversion generated an error, print it
        else  

            if response.statusCode == 200, print the dictionary
            else print the dictionary   
}];
Clone this wiki locally