Sample code for 30+ languages & platforms
Objective-C

Example: JsonObject.NewObjectOf method

Demonstrates the NewObjectOf method.

Chilkat Objective-C Downloads

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

BOOL success = NO;

NSString *car = @"{\"make\":\"Toyota\",\"model\":\"Camry\",\"year\":2022,\"color\":\"silver\",\"engine\":{\"type\":\"inline-4\",\"fuel\":\"gasoline\",\"horsepower\":203},\"features\":[\"bluetooth\",\"backup camera\",\"adaptive cruise control\",\"lane assist\"],\"isElectric\":false}";

CkoJsonObject *json = [[CkoJsonObject alloc] init];

[json UpdateString: @"test" value: @"abc"];

success = [json NewObjectOf: @"car" jObj: car];
if (success == NO) {
    NSLog(@"%@",json.LastErrorText);
    return;
}

json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);

//  Result:

//  {
//    "test": "abc",
//    "car": {
//      "make": "Toyota",
//      "model": "Camry",
//      "year": 2022,
//      "color": "silver",
//      "engine": {
//        "type": "inline-4",
//        "fuel": "gasoline",
//        "horsepower": 203
//      },
//      "features": [
//        "bluetooth",
//        "backup camera",
//        "adaptive cruise control",
//        "lane assist"
//      ],
//      "isElectric": false
//    }
//  }