Skip to content

Commit a8dcadd

Browse files
2.3
1 parent 470badb commit a8dcadd

File tree

6 files changed

+192
-84
lines changed

6 files changed

+192
-84
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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"]}';
6060
var_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
```
6363
It 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.
6868
var_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

7483
Encode 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

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
},
3030
"suggest": {
3131
"ext-mbstring": "*"
32+
},
33+
"require-dev": {
34+
"phpunit/phpunit": "^9.5"
3235
}
3336
}

examples/example_decode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
echo "</pre>";
1111
echo "Decode as array:<br>";
1212
echo "<pre>";
13-
var_dump(Services_JSON::decode($json, Services_JSON::SERVICES_JSON_AS_ARRAY));
13+
var_dump(Services_JSON::decode($json, Services_JSON::GET_ARRAY));
1414
echo "</pre>";

examples/example_decode_unquoted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
echo "</pre>";
1717
echo "Decode as array:<br>";
1818
echo "<pre>";
19-
var_dump(Services_JSON::decode($json,Services_JSON::SERVICES_JSON_AS_ARRAY));
19+
var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY));
2020
echo "</pre>";

0 commit comments

Comments
 (0)