Sample code for 30+ languages & platforms
PureBasic

JSON Append String Array

See more JSON Examples

Demonstrates how to append an array of strings from a string table object.

Note: This example uses the AppendStringTable method, which was introduced in Chilkat v9.5.0.67

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringTable.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::setCkEmitCompact(json, 0)

    CkJsonObject::ckAppendString(json,"abc","123")

    st.i = CkStringTable::ckCreate()
    If st.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkStringTable::ckAppend(st,"a")
    CkStringTable::ckAppend(st,"b")
    CkStringTable::ckAppend(st,"c")
    CkStringTable::ckAppend(st,"d")

    CkJsonObject::ckAppendStringArray(json,"strArray",st)

    Debug CkJsonObject::ckEmit(json)

    ; Output:

    ; 	{
    ; 	  "abc": "123",
    ; 	  "strArray": [
    ; 	    "a",
    ; 	    "b",
    ; 	    "c",
    ; 	    "d"
    ; 	  ]
    ; 	}


    CkJsonObject::ckDispose(json)
    CkStringTable::ckDispose(st)


    ProcedureReturn
EndProcedure