(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 <CkJsonObject.h>
void ChilkatSample(void)
{
// Create JSON with members of different data types.
CkJsonObject json;
json.UpdateInt("a",123);
json.UpdateBool("b",true);
json.UpdateNull("c");
json.put_EmitCompact(false);
std::cout << json.emit() << "\r\n";
// Resulting JSON:
// {
// "a": 123,
// "b": true,
// "c": null
// }
const char *a = json.stringOf("a");
std::cout << a << "\r\n";
const char *b = json.stringOf("b");
std::cout << b << "\r\n";
const char *c = json.stringOf("c");
std::cout << c << "\r\n";
// 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("a");
bool bval = json.BoolOf("b");
bool hasNull = json.IsNullOf("c");
}
|