Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: NSJSONSerialization results in "data paremeter is nil' [closed]

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?

like image 555
Matthew Avatar asked Dec 21 '22 06:12

Matthew


1 Answers

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 ;-) .

like image 85
aleroot Avatar answered Dec 24 '22 11:12

aleroot