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

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    var big_cats: String? = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]"

    let json = CkoJsonObject()!

    json.updateString(jsonPath: "test", value: "abc")

    success = json.newArray(of: "big_cats", jArr: big_cats)
    if success == false {
        print("\(json.lastErrorText!)")
        return
    }

    json.emitCompact = false
    print("\(json.emit()!)")

    //  Result:

    //  {
    //    "test": "abc",
    //    "big_cats": [
    //      "lion",
    //      "tiger",
    //      "leopard",
    //      "jaguar",
    //      "cheetah",
    //      "snow leopard",
    //      "clouded leopard",
    //      "cougar",
    //      "puma",
    //      "panther"
    //    ]
    //  }

}