JsonHelper

Type
Class
Namespace
Craft
Inherits
Craft\JsonHelper » CJSON (opens new window)
Since
1.0

Class JsonHelper

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
decode() (opens new window) Decodes a JSON string into appropriate variable
encode() (opens new window) Encodes an arbitrary variable into JSON format
removeComments() Will remove single-line, multi-line, //, /*, comments from JSON (since comments technically product invalid JSON).
sendJsonHeaders() Sets the Content-Type header to 'application/json' and the Expires, Cache-Control, and Pragma headers to the appropriate vales so the client doesn’t cache the response.
setJsonContentTypeHeader() Sets the Content-Type header to 'application/json'.

# removeComments()

Will remove single-line, multi-line, //, /*, comments from JSON (since comments technically product invalid JSON).

View source (opens new window)

Arguments

  • $json

Returns

mixed, string (opens new window)

Signature

public static mixed, string removeComments ( $json )

# sendJsonHeaders()

Sets the Content-Type header to 'application/json' and the Expires, Cache-Control, and Pragma headers to the appropriate vales so the client doesn’t cache the response.

View source (opens new window)

Returns

void

Signature

public static void sendJsonHeaders ( )

# setJsonContentTypeHeader()

Sets the Content-Type header to 'application/json'.

View source (opens new window)

Signature

public static void setJsonContentTypeHeader ( )

# Protected Methods

Method Description
nameValue() (opens new window) Array-walking function for use in generating JSON-formatted name-value pairs
reduceString() (opens new window) Reduce a string by removing leading and trailing comments and whitespace
unicodeToUTF8() (opens new window) This function converts a Unicode array back to its UTF-8 representation
utf16beToUTF8() (opens new window) UTF-8 to UTF-16BE conversion.
utf8ToUTF16BE() (opens new window) UTF-8 to UTF-16BE conversion.
utf8ToUnicode() (opens new window) This function returns any UTF-8 encoded text as a list of Unicode values:

# Constants

Constant Description
JSON_IN_ARR Marker constant for JSON::decode(), used to flag stack state
JSON_IN_CMT Marker constant for JSON::decode(), used to flag stack state
JSON_IN_OBJ Marker constant for JSON::decode(), used to flag stack state
JSON_IN_STR Marker constant for JSON::decode(), used to flag stack state
JSON_SLICE Marker constant for JSON::decode(), used to flag stack state