2012-11-05 145 views
0

IAM正从Web服务的数据,但它是在URL请求坠毁看到下面的代码应用程序崩溃的原因异常NSInvalidArgumentException

- (void)loadDataSource 
{ 

    // Request 
    NSString *URLPath = [NSString stringWithFormat:@"http://imgur.com/gallery.json"]; 
    NSURL *URL = [NSURL URLWithString:URLPath]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; 

**CRASHED HERE** [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 

     NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode]; 

     if (!error && responseCode == 200) { 
      id res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
      if (res && [res isKindOfClass:[NSDictionary class]]) { 
       self.items = [res objectForKey:@"gallery"]; 
       [self dataSourceDidLoad]; 
      } else { 
       [self dataSourceDidError]; 
      } 
     } else { 
      [self dataSourceDidError]; 
     } 
    }]; 
}  

请帮我提前

回答

0

感谢你代码是正确的,但是结果中没有key @“gallery”的对象。看起来关键是@“数据”。因此,将您的代码更改为

self.items = [res objectForKey:@"data"] 
+0

好的我现在会改变 – kishore

+0

非常感谢你 – kishore

相关问题