dmitrirussu/rjson-php

将数组集合数据压缩为json

dev-master 2017-10-20 07:17 UTC

This package is auto-updated.

Last update: 2024-09-24 09:53:49 UTC


README

GitHub version

PHP5 RJson 版本 1.0.2

版权所有 (c) 2013, Dmitri Russu dmitri.russu@gmail.com RJson 通过算法 Dmytro Dogadailo 返回紧凑的递归数据数组或对象数组。RJson 可以压缩任何同构集合,以及任何具有自由结构的任何数据集。entropyhacker@gmail.com.

=== 将数组数据和Json数据压缩到60%!

RJSON-php VS RJSON-js

如何开始使用PHP RJSON示例

    $data = //Your recursive Array data;
    $pack = RJson::pack($data);
    $unpack = RJson::unpack($pack);

如何开始使用JavaScript RJSON示例

    data = //jason packedge from php;
    unpack = RJSON.unpack(data);
    packAndSendToSerevr = RJSON.pack(unpack);

...

---------------------------------------------------------------------------------------
JavaScrip RJSON release https://github.com/dogada/RJSON from Dmytro Dogadailo.
---------------------------------------------------------------------------------------

RJson可以将任何数组数据集合转换为更紧凑的递归形式。压缩后的数据仍然是JSON,可以使用JSON.parse进行解析。RJson不仅可以压缩同构集合,还可以压缩任何具有自由结构的任何数据集。

下面您可以看到初始形式!

    Array:
	$data['data_process'] = array(
	'template' => array('layers' => array(
	'layer_id_one' => array('age' => 23,'name' => 'Robert',  'height' => 187),
	'layer_id_two' => array('name' => 'Andre', 'age' => 24, 'height' => 188),
	),
	'themes_one' => array(
	'theme_id_one' => array('name' => 'Green', 'width' => 11),
	'theme_id_two' => array('name' => 'Yellow', 'width' => 12),
	),
	'themes_two' => array(
	'theme_id_one' => array('name' => 'Green', 'width' => 11),
	'theme_id_two' => array('name' => 'Yellow', 'width' => 12),
	),
	'designs' => array(
	array('title' => 'Design_1', 'width' => 23, 'height' => 187),
	array('width' => 24, 'title' => 'Design_2','height' => 181),
	)
	),
	'id' => 7,
	'tags' => array('php', 'javascript', 2013, null, false, true),
	'users' => array(
	array('first' => 'Homer', 'last' => 'Simpson'),
	array('first' => 'Hank', 'last' => 'Hill'),
	),
	'library' => array(
	array('title' => 'RJSON-php', 'author' => 'Dmitri Russu', 'year' => 2013),
	array('title' => 'JavaScrip RJSON', 'author' => 'Dmytro Dogadailo', 'year' => 2012))
	);

RJson结果紧凑json或一个紧凑的php数组()

RJson ENCODED Packedge
	{"id":7,
		"library":
			[{"author":"Dmitri Russu","title":"RJSON-php","year":2013},
			[3,"Dmytro Dogadailo","JavaScrip RJSON",2012]],
		"tags":
			["php","javascript",2013,null,false,true],
		"template":{
			"designs":
				[{"height":187,"title":"Design_1","width":23},
				[5,181,"Design_2",24]],
			"layers":{
				"layer_id_one":{"age":23,"height":187,"name":"Robert"},
				"layer_id_two":[7,24,188,"Andre"]},
			"themes_one":
				{"theme_id_one":{"name":"Green","width":11},
				"theme_id_two":[9,"Yellow",12]},
			"themes_two":
				[8,[9,"Green",11],
				[9,"Yellow",12]]},
			"users":
				[{"first":"Homer","last":"Simpson"},
				[10,"Hank","Hill"]]}

使用RJson的示例

您通过一个简单的单例请求调用类

    $data = array(
    'projects' => Db_Model_Projects::findAllProjects($returnArrayRows),
    'settings' => Db_Model_Settings::findAllSettings($returnArrayRows),
    'pages' => Db_Model_Pages::findAllPages($returnArrayRows)
    );

    $compactArrayPackedge = RJson::pack($data);
    
    $compactJsonFormatPackedge = RJson::pack($data, $json = true);
    $compactJsonFormatPackedge - this packedge you can send to Ajax request Where can make unpack with Js library
    *
    * <scrip language="JavaScript" type="text/javascript" >
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": 'index.php?action=getData',
    "success": function(data) {
    packedge = RJSON.unpack(data);
    console.dir(packedge);
    }
    });
    
    //Send packedge to server
    packedge = RJSON.pack(data);
    
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "data": data,
    "url": 'index.php?action=saveData',
    "success": function(result) {
    console.log(result);
    }
    });
    
    <script>

RJson is a good practice to use on your Applications which make requests at server for obtains a big data
to client Application.