PHP code example of atiksoftware / gson-php

1. Go to this page and download the library: Download atiksoftware/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/ */

    

atiksoftware / 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