@@ -53,22 +53,31 @@ See the folder examples for further examples
5353
5454### Decode
5555
56- Decode transform (de-codified) a JSON string into a stdclass or an associative array
56+ Decode a JSON string into a stdclass or an associative array
5757
5858``` php
5959$json='{"hello":{"a":2,"b":3},"world":[1,2,3,"aaa"]}';
6060var_dump(Services_JSON::decode($json)); // as stdclass
61- var_dump(Services_JSON::decode($json,Services_JSON::SERVICES_JSON_AS_ARRAY )); // as array
61+ var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY )); // as array
6262```
6363It also works with unquoted keys
6464
6565``` php
6666
6767$json='{hello:{a:2,b:3},world:[1,2,3,"aaa","bbbb"]}'; // the keys are unquoted.
6868var_dump(Services_JSON::decode($json)); // as stdclass
69- var_dump(Services_JSON::decode($json,Services_JSON::SERVICES_JSON_AS_ARRAY )); // as array
69+ var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY )); // as array
7070```
7171
72+ It also works (with the flag Services_JSON::DECODE_FIX_ROOT) where the string misses [ ] and {} at the start of the code
73+
74+ ``` php
75+ Services_JSON::decode('1,2,3',Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT); // returns [1,2,3]
76+ Services_JSON::decode('"k1":"v1", k2:2',Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT) // returns [ 'k1' => 'v1','k2'=>2]
77+ ```
78+
79+
80+
7281### Encode
7382
7483Encode transform a value (array, object, primitive value, etc.) into a json expression (a string)
@@ -83,7 +92,10 @@ var_dump(Services_JSON::encode($obj)); // encode an object
8392
8493## Changelog
8594
86- * 2.0
95+ * 2.3
96+ * Fixed a typo with a comment.
97+ * added phpunit. The entire code is tested but special codification.
98+ * 2.2
8799 * Now the library is static, so you can call the methods without creating an instance.
88100 * If you want to work with the non-static library, then install 1.1
89101* 1.1
0 commit comments