Sample code for 30+ languages & platforms
Objective-C

Create a JSON Array Containing an Object

See more JSON Examples

Creates a top-level JSON array containing an object.

Chilkat Objective-C Downloads

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

CkoJsonArray *jArray = [[CkoJsonArray alloc] init];

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[jArray AddObjectAt2: [NSNumber numberWithInt: 0] json: json];

[json UpdateString: @"groupId" value: @""];
[json UpdateString: @"sku" value: @""];
[json UpdateString: @"title" value: @""];
[json UpdateString: @"barcode" value: @""];
[json UpdateString: @"category" value: @""];
[json UpdateString: @"description" value: @""];
[json UpdateString: @"images[0]" value: @"url1"];
[json UpdateString: @"images[1]" value: @"url..."];
[json UpdateString: @"isbn" value: @""];
[json UpdateString: @"link" value: @""];
[json UpdateString: @"linkLomadee" value: @""];
[json UpdateString: @"prices[0].type" value: @""];
[json UpdateNumber: @"prices[0].price" numericStr: @"0"];
[json UpdateNumber: @"prices[0].priceLomadee" numericStr: @"0"];
[json UpdateNumber: @"prices[0].priceCpa" numericStr: @"0"];
[json UpdateNumber: @"prices[0].installment" numericStr: @"0"];
[json UpdateNumber: @"prices[0].installmentValue" numericStr: @"0"];
[json UpdateString: @"productAttributes.\"Atributo 1\"" value: @"Valor 1"];
[json UpdateString: @"productAttributes.\"Atributo ...\"" value: @"Valor ..."];
[json UpdateString: @"technicalSpecification.\"Especificação 1\"" value: @"Valor"];
[json UpdateString: @"technicalSpecification.\"Especificação ...\"" value: @"Valor ..."];
[json UpdateNumber: @"quantity" numericStr: @"0"];
[json UpdateNumber: @"sizeHeight" numericStr: @"0"];
[json UpdateNumber: @"sizeLength" numericStr: @"0"];
[json UpdateNumber: @"sizeWidth" numericStr: @"0"];
[json UpdateNumber: @"weightValue" numericStr: @"0"];
[json UpdateNumber: @"declaredPrice" numericStr: @"0"];
[json UpdateNumber: @"handlingTimeDays" numericStr: @"0"];
[json UpdateBool: @"marketplace" value: NO];
[json UpdateString: @"marketplaceName" value: @""];

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

// The output of this program is:

// [
//   {
//     "groupId": "",
//     "sku": "",
//     "title": "",
//     "barcode": "",
//     "category": "",
//     "description": "",
//     "images": [
//       "url1",
//       "url..."
//     ],
//     "isbn": "",
//     "link": "",
//     "linkLomadee": "",
//     "prices": [
//       {
//         "type": "",
//         "price": 0,
//         "priceLomadee": 0,
//         "priceCpa": 0,
//         "installment": 0,
//         "installmentValue": 0
//       }
//     ],
//     "productAttributes": {
//       "Atributo 1": "Valor 1",
//       "Atributo ...": "Valor ..."
//     },
//     "technicalSpecification": {
//       "Especificação 1": "Valor",
//       "Especificação ...": "Valor ..."
//     },
//     "quantity": 0,
//     "sizeHeight": 0,
//     "sizeLength": 0,
//     "sizeWidth": 0,
//     "weightValue": 0,
//     "declaredPrice": 0,
//     "handlingTimeDays": 0,
//     "marketplace": false,
//     "marketplaceName": ""
//   }
// ]