Xbase++
Xbase++
JSON: Renaming and Deleting Members
See more JSON Examples
Demonstrates renaming and deleting members. This example uses the following JSON document:
{
"apple": "red",
"lime": "green",
"banana": "yellow",
"broccoli": "green",
"strawberry": "red"
}
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oJson
nSuccess := 0
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJson:Load('{"apple": "red","lime": "green","banana": "yellow","broccoli": "green","strawberry": "red"}')
IF (nSuccess != 1)
? oJson:LastErrorText
oJson:destroy()
RETURN
ENDIF
// Rename "lime" to "lemon".
nSuccess := oJson:Rename("lime", "lemon")
// Change the color to yellow:
nSuccess := oJson:SetStringOf("lemon", "yellow")
// Rename by index. Banana is at index 2 (apple is at index 0)
nSuccess := oJson:RenameAt(2, "bartlett_pear")
// Delete broccoli by name
nSuccess := oJson:Delete("broccoli")
// Delete apple by index. Apple is at index 0.
nSuccess := oJson:DeleteAt(0)
oJson:EmitCompact := 0
? oJson:Emit()
oJson:destroy()