Swift
Swift
Create JSON Document
See more JSON Examples
Sample code to create the following JSON document:
{
"Title": "Pan's Labyrinth",
"Director": "Guillermo del Toro",
"Original_Title": "El laberinto del fauno",
"Year_Released": 2006
}
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let json = CkoJsonObject()!
// The only reason for failure in the following lines of code would be an out-of-memory condition..
// An index value of -1 is used to append at the end.
success = json.addString(at: -1, name: "Title", value: "Pan's Labyrinth")
success = json.addString(at: -1, name: "Director", value: "Guillermo del Toro")
success = json.addString(at: -1, name: "Original_Title", value: "El laberinto del fauno")
success = json.addInt(at: -1, name: "Year_Released", value: 2006)
json.emitCompact = false
print("\(json.emit()!)")
}