(Unicode C) JSON AppendObject Example
Demonstrates the AppendObject function.
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkJsonObjectW json;
HCkJsonObjectW jObj;
json = CkJsonObjectW_Create();
CkJsonObjectW_Load(json,L"{ \"name\": \"John\", \"marbles\": 100 }");
// Append an empty object named "addr"
jObj = CkJsonObjectW_AppendObject(json,L"addr");
wprintf(L"%s\n",CkJsonObjectW_emit(json));
// Expected output is: {"name":"John","marbles":100,"addr":{}}
// Add members to the object.
CkJsonObjectW_AppendString(jObj,L"street",L"1200 Elm St.");
CkJsonObjectW_AppendString(jObj,L"city",L"Springfield");
CkJsonObjectW_AppendInt(jObj,L"zip",60606);
wprintf(L"%s\n",CkJsonObjectW_emit(json));
// Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
CkJsonObjectW_Dispose(jObj);
CkJsonObjectW_Dispose(json);
}
|