(Perl) Using JSON StringOf with Non-String Members
If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.
use chilkat();
# Create JSON with members of different data types.
$json = chilkat::CkJsonObject->new();
$json->UpdateInt("a",123);
$json->UpdateBool("b",1);
$json->UpdateNull("c");
$json->put_EmitCompact(0);
print $json->emit() . "\r\n";
# Resulting JSON:
# {
# "a": 123,
# "b": true,
# "c": null
# }
$a = $json->stringOf("a");
print $a . "\r\n";
$b = $json->stringOf("b");
print $b . "\r\n";
$c = $json->stringOf("c");
print $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
$ival = $json->IntOf("a");
$bval = $json->BoolOf("b");
$hasNull = $json->IsNullOf("c");
|