Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    const wchar_t *jsonStr;

    success = FALSE;

    rest = CkRestW_Create();
    bTls = TRUE;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"example.com",443,bTls,bAutoReconnect);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  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 = CkJsonObjectW_Create();
    CkRestW_GetLastJsonData(rest,json);

    CkJsonObjectW_putEmitCompact(json,FALSE);
    jsonStr = CkJsonObjectW_emit(json);
    wprintf(L"%s\n",jsonStr);
    //  JSON parsing code for this result can be generated at Chilkat's online tool:
    //  https://tools.chilkat.io/jsonParse


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);

    }