(PureBasic) JSON AppendObject Example
Demonstrates the AppendObject function.
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 object named "addr"
jObj.i = CkJsonObject::ckAppendObject(json,"addr")
Debug CkJsonObject::ckEmit(json)
; Expected output is: {"name":"John","marbles":100,"addr":{}}
; Add members to the object.
CkJsonObject::ckAppendString(jObj,"street","1200 Elm St.")
CkJsonObject::ckAppendString(jObj,"city","Springfield")
CkJsonObject::ckAppendInt(jObj,"zip",60606)
Debug CkJsonObject::ckEmit(json)
; Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
CkJsonObject::ckDispose(jObj)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
|