From 6591bac996e4dd80a39cc795b8e7bd8858cac015 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Sat, 3 Mar 2018 03:06:33 +0300 Subject: [PATCH] Initial Commit --- examples/basic-usage.php | 25 +++++++++++++++++ examples/use-with-classes.php | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 examples/use-with-classes.php diff --git a/examples/basic-usage.php b/examples/basic-usage.php index 8b13789..75ee392 100644 --- a/examples/basic-usage.php +++ b/examples/basic-usage.php @@ -1 +1,26 @@ +addNumber('my-number', 34); + +//add a boolean with 'false' as its value. +$j->addBoolean('my-boolean', FALSE); + +//add a string +$j->addString('a-string', 'Hello, I\'m JsonX! I like "json". '); + +header('content-type:application/json'); +//display json object in the browser. +echo $j; diff --git a/examples/use-with-classes.php b/examples/use-with-classes.php new file mode 100644 index 0000000..4f3f053 --- /dev/null +++ b/examples/use-with-classes.php @@ -0,0 +1,52 @@ +username; + } + public function setUsername($username){ + $this->username = $username; + } + + public function setEmail($email){ + $this->email = $email; + } + + //this function is from the interface JsonI + // it must return JsonX object + public function toJSON(){ + $retVal = new JsonX(); + $retVal->addString('username', $this->username); + $retVal->addString('email', $this->email); + return $retVal; + } +} +$user = new User(); +$user->setEmail('example@example.com'); +$user->setUsername('Warrior Vx'); + +$json = new JsonX(); +$json->addBoolean('my-boolean'); +$json->addObject('user', $user); + +//adding arrays +$json->addArray('my-arr', array(1,2,"hello",array("nested array"))); + +header('content-type:application/json'); +//display json object in the browser. +echo $json;