Ext JS 4.1.3 Sencha Docs

Ext.JSON

Files

Modified version of Douglas Crockford's JSON.js that doesn't mess with the Object prototype.

Available since: 4.0.0

Defined By

Methods

Ext.JSON
view source
( json, [safe] ) : Object
Decodes (parses) a JSON string to an object. ...

Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set.

Available since: 4.0.0

Parameters

  • json : String

    The JSON string

  • safe : Boolean (optional)

    True to return null, false to throw an exception if the JSON is invalid.

    Defaults to: false

Returns

Ext.JSON
view source
( o ) : String
Encodes an Object, Array or other value. ...

Encodes an Object, Array or other value.

If the environment's native JSON encoding is not being used (Ext.USE_NATIVE_JSON is not set, or the environment does not support it), then ExtJS's encoding will be used. This allows the developer to add a toJSON method to their classes which need serializing to return a valid JSON representation of the object.

Available since: 4.0.0

Parameters

  • o : Object

    The variable to encode

Returns

Encodes a Date. ...

Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression. The returned value includes enclosing double quotation marks.

The default return format is "yyyy-mm-ddThh:mm:ss".

To override this:

Ext.JSON.encodeDate = function(d) {
    return Ext.Date.format(d, '"Y-m-d"');
};

Available since: 4.0.0

Parameters

  • d : Date

    The Date to encode

Returns

  • String

    The string literal to use in a JSON string.

Encodes a String. ...

Encodes a String. This returns the actual string which is inserted into the JSON string as the literal expression. The returned value includes enclosing double quotation marks.

To override this:

Ext.JSON.encodeString = function(s) {
    return 'Foo' + s;
};

Available since: 4.1.1

Parameters

  • s : String

    The String to encode

Returns

  • String

    The string literal to use in a JSON string.

The function which encode uses to encode all javascript values to their JSON representations when Ext.USE_NATIVE_JSON...

The function which encode uses to encode all javascript values to their JSON representations when Ext.USE_NATIVE_JSON is false.

This is made public so that it can be replaced with a custom implementation.

Available since: 4.1.0

Parameters

  • o : Object

    Any javascript value to be converted to its JSON representation

Returns

  • String

    The JSON representation of the passed value.