Xbase++ Requires Chilkat v11.4.0+
Xbase++
Example: JsonObject.NewObjectOf method
Demonstrates theNewObjectOf method.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL cCar
LOCAL oJson
nSuccess := 0
cCar := '{"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}'
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("test", "abc")
nSuccess := oJson:NewObjectOf("car", cCar)
IF (nSuccess == 0)
? oJson:LastErrorText
oJson:destroy()
RETURN
ENDIF
oJson:EmitCompact := 0
? oJson: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
// }
// }
oJson:destroy()