title: Convert an iOS objective c object to a JSON string
body: <p>I have an objective C class like,</p>
  
  <pre><code>@interface message : NSObject {
   NSString *from;
   NSString *date;
   NSString *msg;
  }
  </code></pre>
  
  <p>I have an NSMutableArray of instances of this message class. I want serialize all the instances in the NSMutableArray into a JSON file, using the new JSONSerialization APIs in iOS 5 SDK. How can I do this ?</p>
  
  <p>Is creating a NSDictionary of each key, by iterating through each instance of the elements in the NSArray ? Can someone help with code of how to solve this ? I am not able to get good results in Google, as "JSON" skews the results to server-side calls and transfer of data instead of serialization. Thanks a lot.</p>
  
  <p>EDIT:</p>
  
  <pre><code>NSError *writeError = nil; 
  NSData *jsonData = [NSJSONSerialization dataWithJSONObject:notifications options:NSJSONWritingPrettyPrinted error:&amp;writeError];
  NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
  NSLog(@"JSON Output: %@", jsonString);
  </code></pre>