title: Parsing a JSON string into three arrays Objective C
body: <p>I am trying to use the data which I read from a text file in objective c. The data I read from the text file is: </p>
  
  <pre><code>{"aps":{"alert":"Test 1!","sound":"beep.wav","badge":5,"Type":"Banking"},"acme1":"bar","acme2":42}|{"aps":{"alert":"Test 2!","sound":"beep.wav","badge":5,"Type":"Banking"},"acme1":"bar","acme2":42}|{"aps":{"alert":"Test 3!","sound":"beep.wav","badge":5,"Type":"Banking"},"acme1":"bar","acme2":42}|{"aps":{"alert":"Test 4!","sound":"beep.wav","badge":5,"Type":"Banking"},"acme1":"bar","acme2":42}|{"aps":{"alert":"Test 5!","sound":"beep.wav","badge":5,"Type":"Banking"},"acme1":"bar","acme2":42}
  </code></pre>
  
  <p>Once read, I split the file into an array with a delimiter of "|". I then want to further separate it into 3 different arrays: banking, fraud and investment based on the key "Type". However I cannot seem to reach parse the JSON string once I split it into the array. My view did load method is below:</p>
  
  <pre><code>- (void)viewDidLoad {
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *fileName = [NSString stringWithFormat:@"%@/AccountNotifications.txt", documentsDirectory];
      NSString *fileContents = [[NSString alloc]  initWithContentsOfFile:fileName usedEncoding:nil error:nil];
      NSArray *fileData = [fileContents componentsSeparatedByString:@"|"];
  
      if (fileContents != NULL)
      {
          bankingNotifications =  [[NSMutableArray alloc] init];
          fraudNotifications =  [[NSMutableArray alloc] init];
          investmentNotifications = [[NSMutableArray alloc] init];        
  
          for (i = 0; i &lt; [fileData count]; i++)
          {
              NSString *notification = fileData[i];
              NSDictionary *json = [notification JSONValue];
              NSArray *items = [json valueForKeyPath:@"aps"];
  
              if ([[[items objectAtIndex:i] objectForKey:@"Type"] isEqual: @"Banking"])
              {
                  [bankingNotifications addObject:fileData[i]];
                  NSLog(@"Added object to banking array");
              }
  
              if ([[[items objectAtIndex:i] objectForKey:@"Type"] isEqual: @"Fraud"])
              {
                  [fraudNotifications addObject:fileData[i]];
                  NSLog(@"Added object to fraud array");
  
              }
  
              if ([[[items objectAtIndex:i] objectForKey:@"Type"] isEqual: @"Investment"])
              {
                  [investmentNotifications addObject:fileData[i]];
                  NSLog(@"Added object to investment array");
  
              }
          } }
  </code></pre>
  
  <p>There is an error with these three lines:</p>
  
  <pre><code>    NSString *notification = fileData[i];
      NSDictionary *json = [notification JSONValue];
      NSArray *items = [json valueForKeyPath:@"aps"];
  </code></pre>
  
  <p>Could you please help me parse the JSON strings into the three mutable arrays? The error I am getting is: </p>
  
  <p><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x1d59db30'</code></p>