:无法识别的select器发送到实例

我想parsing一个Json文件到表视图,我得到这个错误

[__NSCFDictionary objectAtIndex:]:无法识别的select器发送到实例,应用程序崩溃。 请帮助我,我是iOS开发新手。

我的代码

@implementation ViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { self.title = @"Feeds"; [super viewDidLoad]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSURL *url = [NSURL URLWithString:@"http://little-people.blogspot.com/feeds/posts /default?alt=json"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { data = [[NSMutableData alloc] init]; NSLog(@"Data Data , %@", data); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData { [data appendData:theData]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; feed = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; NSLog(@"Data , %@", feed); [mainTableView reloadData]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The download could not complete - please make sure you're connected to either 3G or Wi-Fi." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [errorView show]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } - (int)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [feed count]; NSLog(@"Data Data , %@", feed); } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; if(cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"]; } if (([feed count] - 1) >=indexPath.row) { cell.textLabel.text = [[feed objectAtIndex:indexPath.row] objectForKey:@"feed"]; cell.detailTextLabel.text = [[feed objectAtIndex:indexPath.row] objectForKey:@"title"]; } return cell; } 

问题是, feed不是一个NSArray ,而是一个NSDictionary

看着JSON,你可能想要访问这个数组: [feed objectForKey:@"entry"]

Feed中的顶级对象是JSON对象,而不是JSON数组。 所以反序列化给你一个NSDictionary,而不是一个NSArray。