Sample code for 30+ languages & platforms
Xbase++

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat Xbase++ Downloads

Xbase++
LOCAL oJson
LOCAL a
LOCAL b
LOCAL c
LOCAL nIval
LOCAL nBval
LOCAL nHasNull

//  Create JSON with members of different data types.
oJson := CreateObject("Chilkat.JsonObject")

oJson:UpdateInt("a", 123)
oJson:UpdateBool("b", 1)
oJson:UpdateNull("c")

oJson:EmitCompact := 0
? oJson:Emit()

//  Resulting JSON:
//  {
//    "a": 123,
//    "b": true,
//    "c": null
//  }

a := oJson:StringOf("a")
? a

b := oJson:StringOf("b")
? b

c := oJson:StringOf("c")
? 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
nIval := oJson:IntOf("a")
nBval := oJson:BoolOf("b")
nHasNull := oJson:IsNullOf("c")

oJson:destroy()