JSON in php

来源:互联网 发布:华为上不了移动网络 编辑:程序博客网 时间:2024/06/06 08:41
This is a good news. PHP 5.2 support json. It's very easy to use. I like it, because I can transfer data between javascript and php freely accroading to this functions.

json_encode

(PHP 5 >= 5.2.0, PECL json:1.2.0-1.2.1)

json_encode — Returns the JSON representation of a value

Description

string json_encode ( mixed $value )

Returns a string containing the JSON representation of value.

Parameters

value

The value being encoded. Can be any type except a resource.

This function only works with UTF-8 encoded data.

Return Values

Returns a JSON encoded string on success.



json_decode

(PHP 5 >= 5.2.0, PECL json:1.2.0-1.2.1)

json_decode — Decodes a JSON string

Description

mixed json_decode ( string $json [, bool $assoc] )

Takes a JSON encoded string and converts it into a PHP variable.

Parameters

json

The json string being decoded.

assoc

When TRUE, returned objects will be converted into associative arrays.

Return Values

Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.




please link to www.php.net for more information.
原创粉丝点击