(PureBasic) Using JSON StringOf with Non-String Members
If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
; Create JSON with members of different data types.
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateInt(json,"a",123)
CkJsonObject::ckUpdateBool(json,"b",1)
CkJsonObject::ckUpdateNull(json,"c")
CkJsonObject::setCkEmitCompact(json, 0)
Debug CkJsonObject::ckEmit(json)
; Resulting JSON:
; {
; "a": 123,
; "b": true,
; "c": null
; }
a.s = CkJsonObject::ckStringOf(json,"a")
Debug a
b.s = CkJsonObject::ckStringOf(json,"b")
Debug b
c.s = CkJsonObject::ckStringOf(json,"c")
Debug c
; Output
; 123
; true
; null
; If you want to get the integer, boolean, or null value
; you need to use the methods matching the data type
ival.i = CkJsonObject::ckIntOf(json,"a")
bval.i = CkJsonObject::ckBoolOf(json,"b")
hasNull.i = CkJsonObject::ckIsNullOf(json,"c")
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
|