PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Ramesh Narayan Jangid   Heavy JSON Decode   README.md   Download  
File: README.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: Heavy JSON Decode
Parse and decode JSON data from a file or string
Author: By
Last change: Refactoring
Refactoring
Date: 9 days ago
Size: 1,204 bytes
 

Contents

Class file image Download

JSON Decode

PHP JSON Decode large data with lesser resources

Examples

Validating JSON.

<?php
require "JsonDecode.php";

// Creating json file handle
$fp = fopen('/usr/local/var/www/rnd/test.json', 'rb');

// Create JsonEncode Object.
$JsonDecode = new JsonDecode($fp);
$JsonDecode->init();

// Validate JSON
$JsonDecode->validate();

$jsonDecode = null;

Accessing data of Array after indexing JSON.

<?php
require "JsonDecode.php";

// Creating json file handle
$fp = fopen('/usr/local/var/www/rnd/test.json', 'rb');

// Create JsonEncode Object.
$JsonDecode = new JsonDecode($fp);
$JsonDecode->init();

// Indexing JSON
$JsonDecode->indexJson();

// Transverse across key 'data'
if ($JsonDecode->isset('data') && $JsonDecode->jsonType('data') === 'Array') {
    for ($i=0, $i_count = $JsonDecode->count('data'); $i < $i_count; $i++) {
        $key = "data:{$i}";

        // Row details without Sub arrays
        $row = $JsonDecode->get($key);
        print_r($row);

        // Row with Sub arrays / Complete $key array recursively.
        $completeRow = $JsonDecode->getCompleteArray($key);
        print_r($completeRow);
    }
}

$jsonDecode = null;