Sample code for 30+ languages & platforms
PureBasic Requires Chilkat v11.4.0+

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    big_cats.s = "[" + Chr(34) + "lion" + Chr(34) + "," + Chr(34) + "tiger" + Chr(34) + "," + Chr(34) + "leopard" + Chr(34) + "," + Chr(34) + "jaguar" + Chr(34) + "," + Chr(34) + "cheetah" + Chr(34) + "," + Chr(34) + "snow leopard" + Chr(34) + "," + Chr(34) + "clouded leopard" + Chr(34) + "," + Chr(34) + "cougar" + Chr(34) + "," + Chr(34) + "puma" + Chr(34) + "," + Chr(34) + "panther" + Chr(34) + "]"

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

    CkJsonObject::ckUpdateString(json,"test","abc")

    success = CkJsonObject::ckNewArrayOf(json,"big_cats",big_cats)
    If success = 0
        Debug CkJsonObject::ckLastErrorText(json)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    CkJsonObject::setCkEmitCompact(json, 0)
    Debug CkJsonObject::ckEmit(json)

    ;  Result:

    ;  {
    ;    "test": "abc",
    ;    "big_cats": [
    ;      "lion",
    ;      "tiger",
    ;      "leopard",
    ;      "jaguar",
    ;      "cheetah",
    ;      "snow leopard",
    ;      "clouded leopard",
    ;      "cougar",
    ;      "puma",
    ;      "panther"
    ;    ]
    ;  }


    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure