Sample code for 30+ languages & platforms
Unicode C++

Load a JSON Array

See more JSON Examples

The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkJsonArrayW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // Imagine we want to load this JSON array for parsing:
    const wchar_t *jsonArrayStr = L"[{\"id\":200},{\"id\":196}]";

    // First wrap it in a JSON object by prepending "{ "array":" and appending "}"
    CkStringBuilderW sbJson;
    sbJson.Append(L"{\"array\":");
    sbJson.Append(jsonArrayStr);
    sbJson.Append(L"}");

    CkJsonObjectW json;
    json.Load(sbJson.getAsString());

    // Now we can get the JSON array
    CkJsonArrayW *jArray = json.ArrayAt(0);

    // Do what you want with the JSON array...
    // For example:
    CkJsonObjectW *jObjId = jArray->ObjectAt(0);
    wprintf(L"%d\n",jObjId->IntOf(L"id"));
    delete jObjId;

    delete jArray;
    }