(PureBasic) JSON AppendArray Example
Demonstrates the AppendArray function.
IncludeFile "CkJsonArray.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(json,"{ " + Chr(34) + "name" + Chr(34) + ": " + Chr(34) + "John" + Chr(34) + ", " + Chr(34) + "marbles" + Chr(34) + ": 100 }")
; Append an empty array named "xyz"
jarr.i = CkJsonObject::ckAppendArray(json,"xyz")
Debug CkJsonObject::ckEmit(json)
; Expected output is: {"name":"John","marbles":100,"xyz":[]}
; Add elements to the array.
CkJsonArray::ckAddStringAt(jarr,-1,"hello")
CkJsonArray::ckAddIntAt(jarr,-1,256)
Debug CkJsonObject::ckEmit(json)
; Expected output is: {"name":"John","marbles":100,"xyz":["hello",256]}
CkJsonArray::ckDispose(jarr)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
|