Objective-C
Objective-C
JSON: Renaming and Deleting Members
See more JSON Examples
Demonstrates renaming and deleting members. This example uses the following JSON document:
{
"apple": "red",
"lime": "green",
"banana": "yellow",
"broccoli": "green",
"strawberry": "red"
}
Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
BOOL success = NO;
CkoJsonObject *json = [[CkoJsonObject alloc] init];
success = [json Load: @"{\"apple\": \"red\",\"lime\": \"green\",\"banana\": \"yellow\",\"broccoli\": \"green\",\"strawberry\": \"red\"}"];
if (success != YES) {
NSLog(@"%@",json.LastErrorText);
return;
}
// Rename "lime" to "lemon".
success = [json Rename: @"lime" newName: @"lemon"];
// Change the color to yellow:
success = [json SetStringOf: @"lemon" value: @"yellow"];
// Rename by index. Banana is at index 2 (apple is at index 0)
success = [json RenameAt: [NSNumber numberWithInt: 2] name: @"bartlett_pear"];
// Delete broccoli by name
success = [json Delete: @"broccoli"];
// Delete apple by index. Apple is at index 0.
success = [json DeleteAt: [NSNumber numberWithInt: 0]];
json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);