예제 #1
0
 public function testObjectJson()
 {
     $json = new Simple\json();
     $object = new stdClass();
     $object->test = 'OK';
     $json->add('An_Object', $object);
     $this->assertEquals($json->make(), '{"An_Object": {"test":"OK"}}');
 }
예제 #2
0
<?php

// The only include you need
include '../includes/json.php';
use Simple;
$json = new Simple\json('var', 'oneVariable');
// Define objects to send
$object = new stdClass();
$object->FirstName = 'John';
$object->LastName = 'Doe';
$array = array(1, '2', 'Pieter', true);
$jsonOnly = '{"Hello" : "darling"}';
// Add objects to send
$json->add('status', '200');
$json->add("worked");
$json->add("things", false);
$json->add('friend', $object);
$json->add("arrays", $array);
$json->add("json", $jsonOnly, false);
/*
  Expected result : 
  var oneVariable = {
    "status": "200",
    "worked": true,
    "things": false,
    "friend": {
        "FirstName": "John",
        "LastName": "Doe"
    },
    "arrays": [
        1,