From 866b6c00f5669de1465f4ec329cb0e46edc07142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Neubauer?= Date: Thu, 23 Feb 2017 13:30:16 +0100 Subject: [PATCH] json.texy translated in english --- en/json.texy | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 en/json.texy diff --git a/en/json.texy b/en/json.texy new file mode 100644 index 0000000000..87e8c5e8b5 --- /dev/null +++ b/en/json.texy @@ -0,0 +1,54 @@ +Working with JSON - Nette\Utils\Json +************************************ + +.[perex] +[Nette\Utils\Json |api:] is a static class with useful functions you can use to work with JSON. It sanitizes errors in different PHP versions and throws exceptions on errors. + +The following examples use these aliases: + +/--php +use Nette\Utils\Json; +use Nette\Utils\JsonException; +\-- + + +encode($value, $options = 0) +============================ + +Returns `$value` encoded into JSON. Accepts argument `Json::PRETTY` which formats JSON for better readability. + +/--php +Json::encode($value); // Returns $value encoded in JSON +Json::encode($value, Json::PRETTY); // Returns formatted $value encoded in JSON +\-- + +Method `encode()` throws `JsonException` on error. + +/--php +try { + Json::encode($value); +} catch (JsonException $e) { + // Exception handling +} +\-- + + +decode($json, $options = 0) +=========================== + +Converts given JSON either in object or in array. Accepts argument `Json::FORCE_ARRAY` which forces an array instead of an object as the return value. + +/--php +Json::decode('{"variable": true}'); // Returns an object of stdClass with attribute $variable +Json::decode('{"variable": true}', Json::FORCE_ARRAY); // Returns an array with key "variable" and value true +\-- + +Method `decode()` throws `JsonException` on error. + +/--php +try { + Json::decode($value); +} catch (JsonException $e) { + // Exception handling +} +\--