(PHP Extension) JSON AppendObject Example
Demonstrates the AppendObject function.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
$json = new CkJsonObject();
$json->Load('{ \'name\': \'John\', \'marbles\': 100 }');
// Append an empty object named "addr"
// jObj is a CkJsonObject
$jObj = $json->AppendObject('addr');
print $json->emit() . "\n";
// Expected output is: {"name":"John","marbles":100,"addr":{}}
// Add members to the object.
$jObj->AppendString('street','1200 Elm St.');
$jObj->AppendString('city','Springfield');
$jObj->AppendInt('zip',60606);
print $json->emit() . "\n";
// Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
?>
|