(C) Example: JsonObject.NewArrayOf method
Demonstrates the NewArrayOf method.Note: This example requires Chilkat v11.4.0 or greater.
#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);
}
|