Sample code for 30+ languages & platforms
Objective-C

Load a JSON Array

See more JSON Examples

The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.

Chilkat Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoJsonArray.h>

BOOL success = NO;

// Imagine we want to load this JSON array for parsing:
NSString *jsonArrayStr = @"[{\"id\":200},{\"id\":196}]";

// First wrap it in a JSON object by prepending "{ "array":" and appending "}"
CkoStringBuilder *sbJson = [[CkoStringBuilder alloc] init];
[sbJson Append: @"{\"array\":"];
[sbJson Append: jsonArrayStr];
[sbJson Append: @"}"];

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json Load: [sbJson GetAsString]];

// Now we can get the JSON array
CkoJsonArray *jArray = [json ArrayAt: [NSNumber numberWithInt: 0]];

// Do what you want with the JSON array...
// For example:
CkoJsonObject *jObjId = [jArray ObjectAt: [NSNumber numberWithInt: 0]];
NSLog(@"%d",[[jObjId IntOf: @"id"] intValue]);