Sample code for 30+ languages & platforms
C

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat C Downloads

C
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    const char *big_cats;
    HCkJsonObject json;

    success = FALSE;

    big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]";

    json = CkJsonObject_Create();

    CkJsonObject_UpdateString(json,"test","abc");

    success = CkJsonObject_NewArrayOf(json,"big_cats",big_cats);
    if (success == FALSE) {
        printf("%s\n",CkJsonObject_lastErrorText(json));
        CkJsonObject_Dispose(json);
        return;
    }

    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    //  Result:

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


    CkJsonObject_Dispose(json);

    }