(Objective-C) Load a JSON Array
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.
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoJsonArray.h>
BOOL success;
// 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]);
|