Sample code for 30+ languages & platforms
PureBasic

Get JSON Details from the Last REST Operation

See more REST Examples

Demonstrates Rest.GetLastJsonData, which copies operation-specific diagnostic or result information from the most recently completed method into a JsonObject. Many methods produce no JSON, in which case the object is empty.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. Some Chilkat operations expose additional structured information as JSON. GetLastJsonData provides access to that information after an operation completes.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    bTls.i = 1
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
    If success = 0
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    ;  Copy operation-specific diagnostic or result information from the most recent method (here the
    ;  Connect call) into a JsonObject.  Many methods produce no JSON, in which case the object is empty.
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkRest::ckGetLastJsonData(rest,json)

    CkJsonObject::setCkEmitCompact(json, 0)
    jsonStr.s = CkJsonObject::ckEmit(json)
    Debug jsonStr
    ;  JSON parsing code for this result can be generated at Chilkat's online tool:
    ;  https://tools.chilkat.io/jsonParse


    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure