PHP
Chilkat2 PHP
Using JSON StringOf with Non-String Members
See more JSON Examples
If a JSON member is a boolean, integer, or null, usingStringOf will return its string representation.
Chilkat PHP Downloads
<?php
use Chilkat2\JsonObject;
// Create JSON with members of different data types.
$json = new JsonObject();
$json->UpdateInt('a', 123);
$json->UpdateBool('b', true);
$json->UpdateNull('c');
$json->EmitCompact = false;
echo $json->Emit(), "\n";
// Resulting JSON:
// {
// "a": 123,
// "b": true,
// "c": null
// }
$a = $json->StringOf('a');
echo $a, "\n";
$b = $json->StringOf('b');
echo $b, "\n";
$c = $json->StringOf('c');
echo $c, "\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');