PHP code example of taquillacom / gson-php

1. Go to this page and download the library: Download taquillacom/gson-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

taquillacom / gson-php example snippets


// $object obtained elsewhere

$gson = Gson::builder()->build();
$json = $gson->toJson($object);

// $object obtained elsewhere

$gson = Gson::builder()->build();
$json = $gson->toJson($object, MyCustomClass::class);

// $json obtained elsewhere

$gson = Gson::builder()->build();
$fooObject = $gson->fromJson($json, Foo::class);

// $object obtained elsewhere

$gson = Gson::builder()->build();
$jsonArray = $gson->toNormalized($object);
$object = $gson->fromNormalized($jsonArray, Foo::class);
bash
composer