JsonHelper

Type
Class
Namespace
Craft
Inherits
Craft\JsonHelper » CJSON
Since
1.0

Class JsonHelper

See also http://craftcms.com

View source

Public Methods

MethodDescription
decode()Decodes a JSON string into appropriate variable
encode()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

Arguments

  • $json

Returns

mixed, string

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

Returns

void

Signature

public static void sendJsonHeaders ( )

setJsonContentTypeHeader()

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

View source

Signature

public static void setJsonContentTypeHeader ( )

Protected Methods

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

Constants

ConstantDescription
JSON_IN_ARRMarker constant for JSON::decode(), used to flag stack state
JSON_IN_CMTMarker constant for JSON::decode(), used to flag stack state
JSON_IN_OBJMarker constant for JSON::decode(), used to flag stack state
JSON_IN_STRMarker constant for JSON::decode(), used to flag stack state
JSON_SLICEMarker constant for JSON::decode(), used to flag stack state