Sample code for 30+ languages & platforms
Objective-C

Create JSON Document

See more JSON Examples

Sample code to create the following JSON document:
{
  "Title": "Pan's Labyrinth",
  "Director": "Guillermo del Toro",
  "Original_Title": "El laberinto del fauno",
  "Year_Released": 2006
}

Chilkat Objective-C Downloads

Objective-C
#import <CkoJsonObject.h>

BOOL success = NO;

CkoJsonObject *json = [[CkoJsonObject alloc] init];

// The only reason for failure in the following lines of code would be an out-of-memory condition..

// An index value of -1 is used to append at the end.
success = [json AddStringAt: [NSNumber numberWithInt: -1] name: @"Title" value: @"Pan's Labyrinth"];
success = [json AddStringAt: [NSNumber numberWithInt: -1] name: @"Director" value: @"Guillermo del Toro"];
success = [json AddStringAt: [NSNumber numberWithInt: -1] name: @"Original_Title" value: @"El laberinto del fauno"];
success = [json AddIntAt: [NSNumber numberWithInt: -1] name: @"Year_Released" value: [NSNumber numberWithInt: 2006]];

json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);