Smutty_Object
|
+--Smutty_JSON
public class Smutty_JSON
extends Smutty_Object
| Method Summary | |
|---|---|
| static mixed | encode(mixed var, mixed use) encodes an arbitrary variable into JSON format |
| private static string | name_value(string name, mixed value) array-walking function for use in generating JSON-formatted name-value pairs |
| private static string | reduce_string(mixed str, $str string) reduce a string by removing leading and trailing comments and whitespace |
| private static string | utf162utf8(string utf16) convert a string from one UTF-16 char to one UTF-8 charNormally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension. |
| private static string | utf82utf16(string utf8) convert a string from one UTF-8 char to one UTF-16 charNormally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension. |
public static mixed encode(mixed var, mixed use)
encodes an arbitrary variable into JSON format
private static string name_value(string name, mixed value)
array-walking function for use in generating JSON-formatted name-value pairs
private static string reduce_string(mixed str, $str string)
reduce a string by removing leading and trailing comments and whitespace
private static string utf162utf8(string 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.
private static string utf82utf16(string 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.
Converts to and from JSON format.
Brief example of use:
// 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 = Smutty_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); /