PHP code example of phpgt / json
1. Go to this page and download the library: Download phpgt/json 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/ */
phpgt / json example snippets
use Gt\Json\JsonObjectBuilder;
use Gt\Json\JsonKvpObject;
use Gt\Json\JsonPrimitive\JsonPrimitive;
$response = file_get_contents("https://example.com/details.json");
$builder = new JsonObjectBuilder();
$jsonObject = $builder->fromJsonString($response);
if($jsonObject instanceof JsonKvpObject) {
$id = $jsonObject->getInt("id");
}
elseif($jsonObject instanceof JsonPrimitive) {
$id = $jsonObject->getPrimitiveValue();
}
echo "Requested ID is: $id";