(AutoIt) 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"
}
$oJson = ObjCreate("Chilkat.JsonObject")
Local $bSuccess = $oJson.Load("{""apple"": ""red"",""lime"": ""green"",""banana"": ""yellow"",""broccoli"": ""green"",""strawberry"": ""red""}")
If ($bSuccess <> True) Then
ConsoleWrite($oJson.LastErrorText & @CRLF)
Exit
EndIf
; Rename "lime" to "lemon".
$bSuccess = $oJson.Rename("lime","lemon")
; Change the color to yellow:
$bSuccess = $oJson.SetStringOf("lemon","yellow")
; Rename by index. Banana is at index 2 (apple is at index 0)
$bSuccess = $oJson.RenameAt(2,"bartlett_pear")
; Delete broccoli by name
$bSuccess = $oJson.Delete("broccoli")
; Delete apple by index. Apple is at index 0.
$bSuccess = $oJson.DeleteAt(0)
$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)
|