(Objective-C) Create JSON Document
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
}
#import <CkoJsonObject.h>
CkoJsonObject *json = [[CkoJsonObject alloc] init];
BOOL success;
// 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]);
|