Object: JSON

JSON decoder and encoder.

JSON Method: encode

Converts an object or array to a JSON string.

Syntax:

var myJSON = JSON.encode(obj);

Аргументы:

  1. obj - (object) The object to convert to string.

Возвращает:

  • (string) A JSON string.

Examples:

var fruitsJSON = JSON.encode({apple: 'red', lemon: 'yellow'}); // returns: '{"apple":"red","lemon":"yellow"}'

JSON Method: decode

Converts a JSON string into a JavaScript object.

Syntax:

var object = JSON.decode(string[, secure]);

Аргументы:

  1. string - (string) The string to evaluate.
  2. secure - (boolean, optional: defaults to false) If set to true, checks for any hazardous syntax and returns null if any found.

Возвращает:

  • (object) The object represented by the JSON string.

Examples:

var myObject = JSON.decode('{"apple":"red","lemon":"yellow"}'); // returns: {apple: 'red', lemon: 'yellow'}

Смотрите также:

Credits:


Эта документация распостраняется на правах Attribution-NonCommercial-ShareAlike 3.0 License.
Оригинал документации на английском.
© Linux.ria.ua, 2008-2024