(Unicode C++) Using JSON StringOf with Non-String Members
If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
// Create JSON with members of different data types.
CkJsonObjectW json;
json.UpdateInt(L"a",123);
json.UpdateBool(L"b",true);
json.UpdateNull(L"c");
json.put_EmitCompact(false);
wprintf(L"%s\n",json.emit());
// Resulting JSON:
// {
// "a": 123,
// "b": true,
// "c": null
// }
const wchar_t *a = json.stringOf(L"a");
wprintf(L"%s\n",a);
const wchar_t *b = json.stringOf(L"b");
wprintf(L"%s\n",b);
const wchar_t *c = json.stringOf(L"c");
wprintf(L"%s\n",c);
// Output
// 123
// true
// null
// If you want to get the integer, boolean, or null value
// you need to use the methods matching the data type
int ival = json.IntOf(L"a");
bool bval = json.BoolOf(L"b");
bool hasNull = json.IsNullOf(L"c");
}
|