(DataFlex) JSON AppendArray Example
Demonstrates the AppendArray function.
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoJson
Boolean iSuccess
Variant vJarr
Handle hoJarr
String sTemp1
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComLoad Of hoJson '{ "name": "John", "marbles": 100 }' To iSuccess
// Append an empty array named "xyz"
Get ComAppendArray Of hoJson "xyz" To vJarr
If (IsComObject(vJarr)) Begin
Get Create (RefClass(cComChilkatJsonArray)) To hoJarr
Set pvComObject Of hoJarr To vJarr
End
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// Expected output is: {"name":"John","marbles":100,"xyz":[]}
// Add elements to the array.
Get ComAddStringAt Of hoJarr -1 "hello" To iSuccess
Get ComAddIntAt Of hoJarr -1 256 To iSuccess
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// Expected output is: {"name":"John","marbles":100,"xyz":["hello",256]}
Send Destroy of hoJarr
End_Procedure
|