Sample code for 30+ languages & platforms
Unicode C

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

Unicode C
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkJsonObjectW json;
    const wchar_t *a;
    const wchar_t *b;
    const wchar_t *c;
    int ival;
    BOOL bval;
    BOOL hasNull;

    //  Create JSON with members of different data types.
    json = CkJsonObjectW_Create();

    CkJsonObjectW_UpdateInt(json,L"a",123);
    CkJsonObjectW_UpdateBool(json,L"b",TRUE);
    CkJsonObjectW_UpdateNull(json,L"c");

    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

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

    a = CkJsonObjectW_stringOf(json,L"a");
    wprintf(L"%s\n",a);

    b = CkJsonObjectW_stringOf(json,L"b");
    wprintf(L"%s\n",b);

    c = CkJsonObjectW_stringOf(json,L"c");
    wprintf(L"%s\n",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
    ival = CkJsonObjectW_IntOf(json,L"a");
    bval = CkJsonObjectW_BoolOf(json,L"b");
    hasNull = CkJsonObjectW_IsNullOf(json,L"c");


    CkJsonObjectW_Dispose(json);

    }