index all rss twitter github linkedin email

Álvaro Ramírez

29 January 2016 Serializing to JSON on iOS

NSDictionary *dictionary = @{
  @"key1" : @"val1\n",
  @"key2" : @"val2\n",
  @"key3" : @"val3\n",
  @"key4" : @"val4\n",
  @"key5" : @"val5\n",
  @"key6" : @"val6\n",
};
NSError *error;
NSData *jsonData =
    [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
if (error) {
  // noooooooooo!
}
NSString *json =
    [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];