rryqszq4/php-cjson

PHP 扩展的快速 JSON 解析和编码支持

dev-master 2017-02-10 00:13 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:09:27 UTC


README

Build Status

php-cjson 是 PHP 扩展的快速 JSON 解析和编码支持。

安装

$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

示例

编码

<?php
$arr = array(
	1,
	"string",
	array("key"=>"value")
);
var_dump(cjson_encode($arr));

/* ==>output
string(28) "[1,"string",{"key":"value"}]";
*/
?>

解码

<?php
$str = '[1,"string",{"key":"value"}]';
var_dump(cjson_decode($str));

/* ==>output
array(3) {
  [0]=>
  int(1)
  [1]=>
  string(6) "string"
  [2]=>
  array(1) {
    ["key"]=>
    string(5) "value"
  }
}
*/
?>