2013-04-30 48 views
4

我有NSURLConnection的和所有在一个视图控制器工作适当的方法。然后我把它移动到UICollectionViewController并获得以下的iOS:NSJSONSerialization导致“数据paremeter是零”

- (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); 
    } 
} 

错误的异常。是: *终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“数据参数是零”

任何人有任何想法

+7

想法:尝试了解异常消息。 – 2013-04-30 06:38:44

+0

我想self.jsonReceivedData无效。这就是为什么它无法序列化。检查你的jsonReceivedData。 – 2013-04-30 06:40:52

+2

你不能要求更好的错误信息.. – Krishnabhadra 2013-04-30 06:41:16

回答

11

异常消息是说给你的变量:self.jsonReceivedData是零,您在调用JSONObjectWithData方法不支持nil数据...

初始化self.jsonReceivedData领域来解决问题;-)。

+0

你是正确的,我忘了这么做,当我移动代码。对我来说愚蠢的错误。谢谢! – 2013-04-30 06:43:28