PHP的json_encode函数和json_decode函数的C语言实现。
C语言是非常强大的,众所周知PHP、MySQL、Apache等等都是由C语言开发然后编译而成的。本源码是PHP的JSON扩展的C语言源码实现。如果你是PHPer,你将更深入的了解C语言是如何强大,也会对PHP的底层代码实现有更深入的了解,这对我们技术的提高有很大帮助。。。
以下为英文介绍:
json 1.2.0
==========
This extension implements the JavaScript Object Notation (JSON)
data-interchange format as specified in [0].
Two functions are implemented: encoding and decoding. The decoding
is handled by a parser based on JSON_checker[1] by Douglas Crockford.
Function overview
-----------------
string json_encode ( mixed value )
json_encode returns a string containing the JSON representation of value.
value can be any type except a resource.
mixed json_decode ( string json, [bool assoc] )
json_decode takes a JSON string and converts it into a PHP variable.
When assoc is given, and evaluates to TRUE, json_decode() will return
any objects as associative arrays.
Example usage
-------------
$arr = array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5);
echo json_encode($arr);
---> {"a":1,"b":2,"c":3,"d":4,"e":5}
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
---> object(stdClass)#1 (5) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
["d"]=>
int(4)
["e"]=>
int(5)
}
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true));
---> array(5) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
["d"]=>
int(4)
["e"]=>
int(5)
}
1