title: Loading JSON Asynchronously on iPhone in UITableView
body: <p>I am trying to load JSON from a sever and then display it in a UITableView. The request goes fine however when I try to add the data to the tableview the app crashes when I call then <code>[tableView reloadData]</code> method is called. I have the variable <code>jsonArray</code> reference in the UITableView methods so that the TableView displays the contents of that variable. Is this the best way to do it and what am I doing wrong?</p>
  
  <p><strong>The connection</strong></p>
  
  <pre><code>NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  </code></pre>
  
  <p><strong>Main HTTP Callback</strong></p>
  
  <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
      [connection release];
  
      NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
      [responseData release];
  
      //Declare the parser
      SBJsonParser *parser = [[SBJsonParser alloc] init];
  
      jsonArray = [parser objectWithString:responseString];
  
      [tableView reloadData];
  
      [parser release];
      [responseString release];
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>2011-07-07 14:42:56.923 Viiad[16370:207] -[__NSSet0 objectAtIndex:]: unrecognized selector sent to instance 0x5a4a0b0
  2011-07-07 14:42:56.925 Viiad[16370:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSet0 objectAtIndex:]: unrecognized selector sent to instance 0x5a4a0b0'
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>UITableViewMethods</strong></p>
  
  <pre><code>// Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      }
  
      NSArray *results = [[jsonArray valueForKey:@"Rows"] valueForKey:@"name"];
  
      cell.textLabel.text = (NSString *)[results objectAtIndex:indexPath.row];
      return cell;
  }
  </code></pre>