dev-master
9999999-dev https://github.com/mikangali-labs/PsonConvert an Object into its JSON representation and vice versa
GNU Lesser General Public License
The Requires
- php >=5.4.0
json
Wallogit.com
2017 © Pedro Peláez
Convert an Object into its JSON representation and vice versa
A PHP library to convert an Object into its JSON representation and vice versa. Use Addendum PHP Lib. The librairy try to do the same job that Java Gson Library., (*1)
Version : 1.0 Require : PHP 5.4 +, (*2)
<?php
//-- Include Pson Lib
require ' Pson/src/Mikangali/Pson/Pson.php';
//-- Simple PHP modele class
class User{
private $_nom; //-- private field
public $_prenom;
/**
* @FieldClass('Voiture')
*/
private $_voiture; //-- complex type field
}
class Voiture {
public $_modele;
public $_prix;
}
//-- json string
$json = '{"_nom":"mike","_prenom":"brandon","_voiture":{"_modele":"Audi A4","_prix":20000}}';
$pson = new Pson();
$user = $pson->fromJson($json,'User');
//-- #1
echo "<pre>"; print_r($user);
//-- #2
echo "<pre>"; print_r($pson->toJson($user));
//-- #1
User Object
(
[_nom:User:private] => mike
[_prenom] => phoenix
[_user] =>
[_voiture:User:private] => Voiture Object
(
[_modele] => Audi A4
[_prix] => 20000
)
)
//-- #2
{"_nom":"mike","_prenom":"phoenix","_voiture":{"_modele":"Audi A4","_prix":20000}}
Pson + Twitter Api, (*3)
(c) 2013 Mikangali Labs, (*4)
Convert an Object into its JSON representation and vice versa
GNU Lesser General Public License
json