SBJsonWriter is a 3rd party JSON library popular years back, now iOS has this built in.
Serialize the data as JSON using the native NSJSONSerialization, and then write it to the keychain (assuming kSecValueData, which is encrypted):
NSArray* array = ...;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:array options:0 error:nil];
NSString* jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[keychainItem setObject:jsonString forKey:(__bridge id)kSecValueData];
To read the data back to an NSArray:
NSString* jsonString = [keychainItem objectForKey:(__bridge id)kSecValueData];
NSArray* array = nil;
if(jsonString.length > 0)
{
id jsonObject = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
// Type check because the JSON serializer can return an array or dictionary
if([jsonObject isKindOfClass:[NSArray class]])
array = jsonObject;
}
// use your array variable here, it may be nil