Sample code for 30+ languages & platforms
Swift Requires Chilkat v11.1.0+

Create a JSON Array Containing an Object

See more JSON Examples

Creates a top-level JSON array containing an object.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let jArray = CkoJsonArray()!

    let json = CkoJsonObject()!
    jArray.addObjectAt2(index: 0, json: json)

    json.updateString(jsonPath: "groupId", value: "")
    json.updateString(jsonPath: "sku", value: "")
    json.updateString(jsonPath: "title", value: "")
    json.updateString(jsonPath: "barcode", value: "")
    json.updateString(jsonPath: "category", value: "")
    json.updateString(jsonPath: "description", value: "")
    json.updateString(jsonPath: "images[0]", value: "url1")
    json.updateString(jsonPath: "images[1]", value: "url...")
    json.updateString(jsonPath: "isbn", value: "")
    json.updateString(jsonPath: "link", value: "")
    json.updateString(jsonPath: "linkLomadee", value: "")
    json.updateString(jsonPath: "prices[0].type", value: "")
    json.updateNumber(jsonPath: "prices[0].price", numericStr: "0")
    json.updateNumber(jsonPath: "prices[0].priceLomadee", numericStr: "0")
    json.updateNumber(jsonPath: "prices[0].priceCpa", numericStr: "0")
    json.updateNumber(jsonPath: "prices[0].installment", numericStr: "0")
    json.updateNumber(jsonPath: "prices[0].installmentValue", numericStr: "0")
    json.updateString(jsonPath: "productAttributes.\"Atributo 1\"", value: "Valor 1")
    json.updateString(jsonPath: "productAttributes.\"Atributo ...\"", value: "Valor ...")
    json.updateString(jsonPath: "technicalSpecification.\"Especificação 1\"", value: "Valor")
    json.updateString(jsonPath: "technicalSpecification.\"Especificação ...\"", value: "Valor ...")
    json.updateNumber(jsonPath: "quantity", numericStr: "0")
    json.updateNumber(jsonPath: "sizeHeight", numericStr: "0")
    json.updateNumber(jsonPath: "sizeLength", numericStr: "0")
    json.updateNumber(jsonPath: "sizeWidth", numericStr: "0")
    json.updateNumber(jsonPath: "weightValue", numericStr: "0")
    json.updateNumber(jsonPath: "declaredPrice", numericStr: "0")
    json.updateNumber(jsonPath: "handlingTimeDays", numericStr: "0")
    json.updateBool(jsonPath: "marketplace", value: false)
    json.updateString(jsonPath: "marketplaceName", value: "")

    jArray.emitCompact = false
    print("\(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": ""
    //    }
    //  ]

}