Flourish PHP Unframework

fJSON

static class, v1.0.0b6

Provides encoding and decoding for JSON

This class is a compatibility class for the json extension on servers with PHP 5.0 or 5.1, or servers with the json extension compiled out.

This class will handle JSON values that are not contained in an array or object - such values are not valid according to the JSON spec, but the functionality is included for compatiblity with the json extension.

Changes:
1.0.0b6Removed e flag from preg_replace() calls 6/8/10
1.0.0b5Added the output() method 3/15/10
1.0.0b4Fixed a bug with decode() where JSON objects could lose all but the first key: value pair 5/6/09
1.0.0b3Updated the class to be consistent with PHP 5.2.9+ for encoding and decoding invalid data 5/4/09
1.0.0b2Changed @ error suppression operator to error_reporting() calls 1/26/09
1.0.0bThe initial implementation 7/12/08

Constants

::J_ARRAY_CLOSE internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of ]

::J_ARRAY_COMMA internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of , in a JSON array

::J_ARRAY_OPEN internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of [

::J_COLON internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of :

::J_FALSE internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of a boolean false

::J_FLOAT internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of a floating value

::J_INTEGER internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of an integer

::J_KEY internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of a JSON object key

::J_NULL internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of null

::J_OBJ_CLOSE internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of }

::J_OBJ_COMMA internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of , in a JSON object

::J_OBJ_OPEN internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of {

::J_STRING internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of a string

::J_TRUE internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

An abstract representation of a boolean true

Static Methods

::decode() public

Decodes a JSON string into native PHP data types

This function is very strict about the format of JSON. If the string is not a valid JSON string, NULL will be returned.

Signature

array|stdClass decode( string $json, boolean $assoc=FALSE )

Parameters

string $json This should be the name of a related class
boolean $assoc If this is TRUE, JSON objects will be represented as an assocative array instead of a stdClass object

Returns

A PHP equivalent of the JSON string

::encode() public

Encodes a PHP value into a JSON string

Signature

string encode( mixed $value )

Parameters

mixed $value The PHP value to encode

Returns

The JSON string that is equivalent to the PHP value

::output() public

Sets the proper Content-Type header and outputs the value, encoded as JSON

Signature

void output( mixed $value )

Parameters

mixed $value The PHP value to output as JSON

::sendHeader() public

Sets the proper Content-Type header for UTF-8 encoded JSON

Signature

void sendHeader( )