예제 #1
0
 public function testObjectJson()
 {
     $json = new json();
     $object = new stdClass();
     $object->test = 'OK';
     $json->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;
$json = new json();
// Ojects to send (fetched from the DB for example)
$object = new stdClass();
$object->LastLog = '123456789123456';
$object->Password = '******';
$object->Dramatic = 'Cat';
$object->Things = array(1, 2, 3);
// Forge the JSON
$json->data = $object;
$json->user = AlexisTM;
$json->status = 'online';
// Send the JSON
$json->send_callback('myAwesomeFunction');
/*
  Expected result : 
   myAwesomeFunction({
   	"data": {
   		"LastLog": "123456789123456",
   		"Password": "******",
   		"Dramatic": "Cat",
   		"Things": [1, 2, 3]
   	},
   	"user": "******",
   	"status": "online"
   });
예제 #3
0
<?php

// The only include you need
include '../includes/json.php';
use Simple\json;
$json = new json();
// Ojects to send (fetched from the DB for example)
$object = new stdClass();
$object->LastLog = '123456789123456';
$object->Password = '******';
$object->Dramatic = 'Cat';
$object->Things = array(1, 2, 3);
// Forge the JSON
$json->data = $object;
$json->user = AlexisTM;
$json->status = 'online';
// Send the JSON
$json->send();
/*
  Expected result : 
   {
   	"data": {
   		"LastLog": "123456789123456",
   		"Password": "******",
   		"Dramatic": "Cat",
   		"Things": [1, 2, 3]
   	},
   	"user": "******",
   	"status": "online"
   }
예제 #4
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,
예제 #5
0
<?php

// The only include you need
include '../includes/json.php';
use Simple\json;
$json = new json();
// Ojects to send (fetched from the DB for example)
$object = new stdClass();
$object->LastLog = '123456789123456';
$object->Password = '******';
$object->Dramatic = 'Cat';
$object->Things = array(1, 2, 3);
// Forge the JSON
$json->data = $object;
$json->user = AlexisTM;
$json->status = 'online';
// Send the JSON
$json->send_var('someVar');
/*
  Expected result : 
   var someVar = {
   	"data": {
   		"LastLog": "123456789123456",
   		"Password": "******",
   		"Dramatic": "Cat",
   		"Things": [1, 2, 3]
   	},
   	"user": "******",
   	"status": "online"
   };