4

I had the NSURLConnection and all the appropriate methods working in one view controller. Then i moved it to a UICollectionViewController and get an exception below

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSError *jsonParsingError = nil;

//error right here!
    NSString
    *object = [NSJSONSerialization JSONObjectWithData:self.jsonReceivedData options:NSJSONReadingMutableContainers error:&jsonParsingError]; 

    if (jsonParsingError) {
        NSLog(@"JSON ERROR: %@", [jsonParsingError localizedDescription]);
    } else {
        NSLog(@"LIST: %@", object);
    }
}

The error is: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

Anyone have any ideas?

Matthew
  • 2,035
  • 4
  • 25
  • 48

1 Answers1

11

The exception message is saying to you that the variable : self.jsonReceivedData is nil, and the method you are calling JSONObjectWithData do not support nil data ...

Initialize self.jsonReceivedData field to resolve the problem ;-) .

aleroot
  • 71,077
  • 30
  • 176
  • 213
  • you are correct, i forgot to do that when i moved code over. Stupid mistake on my part. Thanks! – Matthew Apr 30 '13 at 06:43