Git Product home page Git Product logo

pson's Introduction

Pson

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.

Version : 1.0 Require : PHP 5.4 +


Features

  • Convert object to json and Json to object
  • Convert PHP object containning private fiels
  • Use annotation to serialize/deserialize complex fileds
  • PsonBuilder class to set Pson options (serializeNulls, excludeModifiers ...)
  • @Expose annotation for managing fields exclusion

Package content

  • ./Pson.class.php : Pson lib class
  • ./addendum/ : Addendum lib used by Pson
  • ./index.php : Pson usage sample

Usage

			<?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));

Ouput

			//-- #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}}

Others samples :

Pson + Twitter Api

(c) 2013 Mikangali Labs

pson's People

Contributors

mikamboo avatar eliesauveterre avatar

Stargazers

Marco Rivadeneyra avatar Steven Wade avatar Alexander Buch avatar GUERET Xavier(HIX) avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.