Services_JSON()
Services_JSON(integer $use)
constructs a new JSON instance
Parameters
integer | $use | object behavior flags; combine with boolean-OR
|
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(integer $use)
constructs a new JSON instance
integer | $use | object behavior flags; combine with boolean-OR
|
utf162utf8(string $utf16) : string
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 |
UTF-8 character
utf82utf16(string $utf8) : string
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 |
UTF-16 character
encode(mixed $var) : mixed
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! |
JSON string representation of input var or an error if a problem occurs
name_value(string $name, mixed $value) : string
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 |
JSON-formatted name-value pair, like '"name":value'
decode(string $str) : mixed
decodes a JSON string into appropriate variable
string | $str | JSON-formatted string |
number, boolean, string, array, or object corresponding to given JSON input string. See argument 1 to Services_JSON() above for object-output behavior. Note that decode() always returns strings in ASCII or UTF-8 format!