Skip to content

Commit c94f754

Browse files
lukasneubauerdg
authored andcommitted
json.texy translated in english (#499)
1 parent 5d366de commit c94f754

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

doc/en/json.texy

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Working with JSON - Nette\Utils\Json
2+
************************************
3+
4+
.[perex]
5+
[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.
6+
7+
The following examples use these aliases:
8+
9+
/--php
10+
use Nette\Utils\Json;
11+
use Nette\Utils\JsonException;
12+
\--
13+
14+
15+
encode($value, $options = 0)
16+
============================
17+
18+
Returns `$value` encoded into JSON. Accepts argument `Json::PRETTY` which formats JSON for better readability.
19+
20+
/--php
21+
Json::encode($value); // Returns $value encoded in JSON
22+
Json::encode($value, Json::PRETTY); // Returns formatted $value encoded in JSON
23+
\--
24+
25+
Method `encode()` throws `JsonException` on error.
26+
27+
/--php
28+
try {
29+
Json::encode($value);
30+
} catch (JsonException $e) {
31+
// Exception handling
32+
}
33+
\--
34+
35+
36+
decode($json, $options = 0)
37+
===========================
38+
39+
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.
40+
41+
/--php
42+
Json::decode('{"variable": true}'); // Returns an object of stdClass with attribute $variable
43+
Json::decode('{"variable": true}', Json::FORCE_ARRAY); // Returns an array with key "variable" and value true
44+
\--
45+
46+
Method `decode()` throws `JsonException` on error.
47+
48+
/--php
49+
try {
50+
Json::decode($value);
51+
} catch (JsonException $e) {
52+
// Exception handling
53+
}
54+
\--

0 commit comments

Comments
 (0)