CJSON
Package | system.web.helpers |
---|---|
Inheritance | class CJSON |
Since | 1.0 |
Version | $Id: CJSON.php 2163 2010-06-04 14:49:37Z alexander.makarow $ |
CJSON converts PHP data to and from JSON format.
Public Methods
Method | Description | Defined By |
---|---|---|
decode() | decodes a JSON string into appropriate variable | CJSON |
encode() | Encodes an arbitrary variable into JSON format | CJSON |
Protected Methods
Method | Description | Defined By |
---|---|---|
nameValue() | array-walking function for use in generating JSON-formatted name-value pairs | CJSON |
reduceString() | reduce a string by removing leading and trailing comments and whitespace | CJSON |
unicodeToUTF8() | This function converts a Unicode array back to its UTF-8 representation | CJSON |
utf16beToUTF8() | UTF-8 to UTF-16BE conversion. | CJSON |
utf8ToUTF16BE() | UTF-8 to UTF-16BE conversion. | CJSON |
utf8ToUnicode() | This function returns any UTF-8 encoded text as a list of | CJSON |
Method Details
decode()
method
public static mixed decode(string $str, boolean $useArray=true)
| ||
$str | string | $str JSON-formatted string |
$useArray | boolean | whether to use associative array to represent object data |
{return} | mixed | number, boolean, string, array, or object corresponding to given JSON input string. See argument 1 to JSON() above for object-output behavior. Note that decode() always returns strings in ASCII or UTF-8 format! |
decodes a JSON string into appropriate variable
encode()
method
public static string encode(mixed $var)
| ||
$var | mixed | $var any number, boolean, string, array, or object to be encoded. see argument 1 to JSON() above for array-parsing behavior. if var is a strng, note that encode() always expects it to be in ASCII or UTF-8 format! |
{return} | string | JSON string representation of input var |
Encodes an arbitrary variable into JSON format
nameValue()
method
protected static string nameValue(string $name, mixed $value)
| ||
$name | string | $name name of key to use |
$value | mixed | $value reference to an array element to be encoded |
{return} | string | JSON-formatted name-value pair, like '"name":value' |
array-walking function for use in generating JSON-formatted name-value pairs
reduceString()
method
protected static string reduceString($str $str)
| ||
$str | $str | string string value to strip of comments and whitespace |
{return} | string | string value stripped of comments and whitespace |
reduce a string by removing leading and trailing comments and whitespace
unicodeToUTF8()
method
protected static void unicodeToUTF8($str)
| ||
$str |
This function converts a Unicode array back to its UTF-8 representation
See Also
utf16beToUTF8()
method
protected static void utf16beToUTF8($str)
| ||
$str |
UTF-8 to UTF-16BE conversion.
Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
utf8ToUTF16BE()
method
protected static void utf8ToUTF16BE($str, $bom=false)
| ||
$str | ||
$bom |
UTF-8 to UTF-16BE conversion.
Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
utf8ToUnicode()
method
protected static void utf8ToUnicode($str)
| ||
$str |
This function returns any UTF-8 encoded text as a list of Unicode values: