(Lianja) JSON: Renaming and Deleting Members
Demonstrates renaming and deleting members.
This example uses the following JSON document:
{
"apple": "red",
"lime": "green",
"banana": "yellow",
"broccoli": "green",
"strawberry": "red"
}
loJson = createobject("CkJsonObject")
llSuccess = loJson.Load('{"apple": "red","lime": "green","banana": "yellow","broccoli": "green","strawberry": "red"}')
if (llSuccess <> .T.) then
? loJson.LastErrorText
release loJson
return
endif
// Rename "lime" to "lemon".
llSuccess = loJson.Rename("lime","lemon")
// Change the color to yellow:
llSuccess = loJson.SetStringOf("lemon","yellow")
// Rename by index. Banana is at index 2 (apple is at index 0)
llSuccess = loJson.RenameAt(2,"bartlett_pear")
// Delete broccoli by name
llSuccess = loJson.Delete("broccoli")
// Delete apple by index. Apple is at index 0.
llSuccess = loJson.DeleteAt(0)
loJson.EmitCompact = .F.
? loJson.Emit()
release loJson
|