title: Complex JSON as NSArray Datasource for a UITableView iOS
body: <p>I tried almost everything before posting (google, Apple Dev Doc etc.). I hope I did not miss anything before posting.. </p>
  
  <p>I already built a working JSON &lt;-> Webservice &lt;-> iPhone login. </p>
  
  <p>with the following code:</p>
  
  <pre><code>NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]autorelease];
  NSDictionary *jsonDict = [responseString JSONValue];
  NSString *loginResult = [jsonDict valueForKey:@"LoginResult"];
  </code></pre>
  
  <p>loginResult is the name of the employee: e.g "Henning Wenger"</p>
  
  <p>The corresponding JSON looks like this: </p>
  
  <pre><code>{"LoginResult":"S:00000412"}
  </code></pre>
  
  <p>Now I have a more complex task which I can´t manage to figure a way through:</p>
  
  <p>I´m getting the following JSON from the webservice:</p>
  
  <pre><code>{"GetTeamPresentStatusResult"[
  {"Firstname":"Steffen","Id":"00000456","IsPresent":"true","Lastname":"Polker"},
  {"Firstname":"Erich","Id":"00000455","IsPresent":"true","Lastname":"Welter"},     
  {"Firstname":"Titus","Id":"00000454","IsPresent":"true","Lastname":"Sommerbeck"},      {"Firstname":"Ruediger","Id":"00000453","IsPresent":"true","Lastname":"Oelmann"},{"Firstname":"Heinz","Id":"00000452","IsPresent":"true","Lastname":"Radelfs"},{"Firstname":"Franz","Id":"00000451","IsPresent":"true","Lastname":"Wippermann"},{"Firstname":"Klaus-Dieter","Id":"00000450","IsPresent":"true","Lastname":"Just"},{"Firstname":"Alan","Id":"00000412","IsPresent":"true","Lastname":"Turing"},{"Firstname":"Konrad","Id":"00000138","IsPresent":"true","Lastname":"Zuse"},{"Firstname":"Marius","Id":"00000112","IsPresent":"true","Lastname":"Sandmann"}]}
  </code></pre>
  
  <p>My code for handling this starts with:</p>
  
  <pre><code>NSDictionary *jsonDict = [responseString JSONValue];
  NSArray *teamStatus = [jsonDict objectForKey:@"GetTeamPresentStatusResult"];
  [self BuildDataSource: nil :teamStatus];
  </code></pre>
  
  <p>teamStatus now contains 10 key/value pairs.</p>
  
  <p>Here is how I tried to build up the datasource for my table:</p>
  
  <pre><code>- (void)BuildDataSource: (id) sender: (NSArray*)teamStatusData{
  
  teamStatusMutableArray = [[NSMutableArray alloc]init];
  teamStatusDataSection = [[NSArray alloc]initWithArray:teamStatusData];
  
  teamStatusDictSectionOne = [NSDictionary dictionaryWithObject:teamStatusDataSection forKey:@"OrgUnits"];
  [teamStatusMutableArray addObject:teamStatusDictSectionOne];
  
  [tblView reloadData];
  }
  </code></pre>
  
  <p>I can not manage to figure out which way to go from here to get the data how I need it.</p>
  
  <p>Do I need different Arrays where one contains the firstname/value and another one that contains lastname/value? If yes, how do I do that?</p>
  
  <p>Here are some lines I´ve tried so far which did not have helped:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  static NSString *CellIdentifier = @"Cell";
  
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
  }
  
  // Set up the cell...
  //First get the dictionary object
  
  NSDictionary *dictionary = [teamStatusMutableArray objectAtIndex:indexPath.section];
  
  NSString *testString = [dictionary valueForKey:@"Firstname"];
  NSArray *testarray = [dictionary objectForKey:@"OrgUnits"];
  
  NSString *test = [testarray JSONRepresentation];
  
  test = [test stringByReplacingOccurrencesOfString:@"[" withString:@""];
  test = [test stringByReplacingOccurrencesOfString:@"]" withString:@""];
  
  NSDictionary *jsonDict = [test JSONValue];
  }
  </code></pre>
  
  <p>What I need is to have a Datasource with the Employee Names that I can bind to a Table. From there I think I can make my way without additional help.</p>
  
  <p>I´m coming from the .NET (C#) world and maybe this confuses me too much.</p>
  
  <p>Thank you so much..</p>
  
  <p>Henning</p>
  
  <p>If you need further details please ask!</p>
  
  <p>Details for SPtail:</p>
  
  <p>Here is the .h file:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "RootViewController.h"
  #import "EmployeeDetails.h"
  
  @interface OrgUnitAA:NSObject {
  NSString *FirstName;
  NSString *Id;
  NSString *IsPresent;
  NSString *LastName;
  }
  
  @property (nonatomic, retain) NSString *FirstName;
  @property (nonatomic, retain) NSString *Id;
  @property (nonatomic, retain) NSString *IsPresent;
  @property (nonatomic, retain) NSString *LastName;
  
  @end
  
  @interface TeamStatusView : UIViewController {
  
  UITableView *tblView;
  NSMutableArray *teamStatusMutableArray;
  NSArray *teamStatusDataSection;
  NSDictionary *teamStatusDictSectionOne;
  UIViewController *EmployeeDetails;
  UIViewController *RootViewController;
  NSMutableData *responseData;
  }
  
  @property (nonatomic, retain) IBOutlet UITableView *tblView;
  @property (nonatomic, retain) NSArray *teamStatusMutableArray;
  @property (nonatomic, retain) NSMutableArray *dummyMutableArrayTimeQuota;
  @property (nonatomic, retain) NSArray *teamStatusDataSection;
  @property (nonatomic, retain) NSDictionary *teamStatusDictSectionOne;
  @property (nonatomic, retain) IBOutlet UIViewController *RootViewController;
  @property (nonatomic, retain) IBOutlet UIViewController *EmployeeDetails;
  
  - (void)GetTeamStatus: id;
  - (void)BuildDataSource: id: (NSArray*)teamStatusData;
  @end
  </code></pre>