ILIAS
eassessment Revision 61809
|
Converts to and from JSON format. More...
Public Member Functions | |
Services_JSON ($use=0) | |
constructs a new JSON instance | |
utf162utf8 ($utf16) | |
convert a string from one UTF-16 char to one UTF-8 char | |
utf82utf16 ($utf8) | |
convert a string from one UTF-8 char to one UTF-16 char | |
encode ($var) | |
encodes an arbitrary variable into JSON format | |
name_value ($name, $value) | |
array-walking function for use in generating JSON-formatted name-value pairs | |
reduce_string ($str) | |
reduce a string by removing leading and trailing comments and whitespace | |
decode ($str) | |
decodes a JSON string into appropriate variable | |
isError ($data, $code=null) | |
Services_JSON ($use=0) | |
constructs a new JSON instance | |
utf162utf8 ($utf16) | |
convert a string from one UTF-16 char to one UTF-8 char | |
utf82utf16 ($utf8) | |
convert a string from one UTF-8 char to one UTF-16 char | |
encode ($var) | |
encodes an arbitrary variable into JSON format | |
name_value ($name, $value) | |
array-walking function for use in generating JSON-formatted name-value pairs | |
reduce_string ($str) | |
reduce a string by removing leading and trailing comments and whitespace | |
decode ($str) | |
decodes a JSON string into appropriate variable | |
isError ($data, $code=null) |
Converts to and from JSON format.
Brief example of use:
// create a new instance of Services_JSON $json = new Services_JSON();
// convert a complexe value to JSON notation, and send it to the browser $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); $output = $json->encode($value);
print($output); // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
// accept incoming POST data, assumed to be in JSON notation $input = file_get_contents('php://input', 1000000); $value = $json->decode($input);
Services_JSON::decode | ( | $str | ) |
decodes a JSON string into appropriate variable
string | $str | JSON-formatted string |
Definition at line 484 of file JSON.php.
References reduce_string(), SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_CMT, SERVICES_JSON_IN_OBJ, SERVICES_JSON_IN_STR, SERVICES_JSON_LOOSE_TYPE, SERVICES_JSON_SLICE, and utf162utf8().
Referenced by decode().
Services_JSON::decode | ( | $str | ) |
decodes a JSON string into appropriate variable
string | $str | JSON-formatted string |
Definition at line 484 of file json.php.
References decode(), reduce_string(), SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_CMT, SERVICES_JSON_IN_OBJ, SERVICES_JSON_IN_STR, SERVICES_JSON_LOOSE_TYPE, SERVICES_JSON_SLICE, and utf162utf8().
Services_JSON::encode | ( | $var | ) |
encodes an arbitrary variable into JSON format
mixed | $var | any number, boolean, string, array, or object to be encoded. see argument 1 to Services_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! |
Definition at line 237 of file json.php.
References isError(), SERVICES_JSON_SUPPRESS_ERRORS, and utf82utf16().
Services_JSON::encode | ( | $var | ) |
encodes an arbitrary variable into JSON format
mixed | $var | any number, boolean, string, array, or object to be encoded. see argument 1 to Services_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! |
Definition at line 237 of file JSON.php.
References isError(), SERVICES_JSON_SUPPRESS_ERRORS, and utf82utf16().
Referenced by name_value().
Services_JSON::isError | ( | $data, | |
$code = null |
|||
) |
Definition at line 766 of file JSON.php.
References $data.
Referenced by encode(), isError(), and name_value().
Services_JSON::isError | ( | $data, | |
$code = null |
|||
) |
Services_JSON::name_value | ( | $name, | |
$value | |||
) |
array-walking function for use in generating JSON-formatted name-value pairs
string | $name | name of key to use |
mixed | $value | reference to an array element to be encoded |
Definition at line 434 of file JSON.php.
References $name, encode(), and isError().
Services_JSON::name_value | ( | $name, | |
$value | |||
) |
array-walking function for use in generating JSON-formatted name-value pairs
string | $name | name of key to use |
mixed | $value | reference to an array element to be encoded |
Definition at line 434 of file json.php.
References $name, encode(), and isError().
Services_JSON::reduce_string | ( | $str | ) |
reduce a string by removing leading and trailing comments and whitespace
$str | string string value to strip of comments and whitespace |
Definition at line 453 of file json.php.
Services_JSON::reduce_string | ( | $str | ) |
reduce a string by removing leading and trailing comments and whitespace
$str | string string value to strip of comments and whitespace |
Definition at line 453 of file JSON.php.
Referenced by decode().
Services_JSON::Services_JSON | ( | $use = 0 | ) |
constructs a new JSON instance
int | $use | object behavior flags; combine with boolean-OR possible values: - SERVICES_JSON_LOOSE_TYPE: loose typing. "{...}" syntax creates associative arrays instead of objects in decode(). - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. Values which can't be encoded (e.g. resources) appear as NULL instead of throwing errors. By default, a deeply-nested resource will bubble up with an error, so all return values from encode() should be checked with isError() |
Definition at line 133 of file json.php.
Services_JSON::Services_JSON | ( | $use = 0 | ) |
constructs a new JSON instance
int | $use | object behavior flags; combine with boolean-OR possible values: - SERVICES_JSON_LOOSE_TYPE: loose typing. "{...}" syntax creates associative arrays instead of objects in decode(). - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. Values which can't be encoded (e.g. resources) appear as NULL instead of throwing errors. By default, a deeply-nested resource will bubble up with an error, so all return values from encode() should be checked with isError() |
Definition at line 133 of file JSON.php.
Services_JSON::utf162utf8 | ( | $utf16 | ) |
convert a string from one UTF-16 char to one UTF-8 char
Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.
string | $utf16 | UTF-16 character |
Definition at line 149 of file JSON.php.
Referenced by decode().
Services_JSON::utf162utf8 | ( | $utf16 | ) |
convert a string from one UTF-16 char to one UTF-8 char
Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.
string | $utf16 | UTF-16 character |
Definition at line 149 of file json.php.
Services_JSON::utf82utf16 | ( | $utf8 | ) |
convert a string from one UTF-8 char to one UTF-16 char
Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.
string | $utf8 | UTF-8 character |
Definition at line 193 of file json.php.
Services_JSON::utf82utf16 | ( | $utf8 | ) |
convert a string from one UTF-8 char to one UTF-16 char
Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.
string | $utf8 | UTF-8 character |
Definition at line 193 of file JSON.php.
Referenced by encode().