(C) JSON AppendObject Example
Demonstrates the AppendObject function.
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkJsonObject json;
HCkJsonObject jObj;
json = CkJsonObject_Create();
CkJsonObject_Load(json,"{ \"name\": \"John\", \"marbles\": 100 }");
// Append an empty object named "addr"
jObj = CkJsonObject_AppendObject(json,"addr");
printf("%s\n",CkJsonObject_emit(json));
// Expected output is: {"name":"John","marbles":100,"addr":{}}
// Add members to the object.
CkJsonObject_AppendString(jObj,"street","1200 Elm St.");
CkJsonObject_AppendString(jObj,"city","Springfield");
CkJsonObject_AppendInt(jObj,"zip",60606);
printf("%s\n",CkJsonObject_emit(json));
// Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
CkJsonObject_Dispose(jObj);
CkJsonObject_Dispose(json);
}
|