Index: trunk/phase3/includes/json/FormatJson.php |
— | — | @@ -7,6 +7,15 @@ |
8 | 8 | } |
9 | 9 | |
10 | 10 | class FormatJson { |
| 11 | + |
| 12 | + /** |
| 13 | + * Returns the JSON representation of a value. |
| 14 | + * |
| 15 | + * @param $value Mixed: the value being encoded. Can be any type except a resource. |
| 16 | + * @param $isHtml Boolean |
| 17 | + * |
| 18 | + * @return string |
| 19 | + */ |
11 | 20 | public static function encode( $value, $isHtml = false ) { |
12 | 21 | // Some versions of PHP have a broken json_encode, see PHP bug |
13 | 22 | // 46944. Test encoding an affected character (U+20000) to |
— | — | @@ -19,6 +28,17 @@ |
20 | 29 | } |
21 | 30 | } |
22 | 31 | |
| 32 | + /** |
| 33 | + * Decodes a JSON string. |
| 34 | + * |
| 35 | + * @param $value String: the json string being decoded. |
| 36 | + * @param $assoc Boolean: when true, returned objects will be converted into associative arrays. |
| 37 | + * |
| 38 | + * @return Mixed: the value encoded in json in appropriate PHP type. |
| 39 | + * Values true, false and null (case-insensitive) are returned as true, false |
| 40 | + * and &null; respectively. &null; is returned if the json cannot be |
| 41 | + * decoded or if the encoded data is deeper than the recursion limit. |
| 42 | + */ |
23 | 43 | public static function decode( $value, $assoc = false ) { |
24 | 44 | if ( !function_exists( 'json_decode' ) ) { |
25 | 45 | $json = new Services_JSON(); |
— | — | @@ -31,4 +51,5 @@ |
32 | 52 | return json_decode( $value, $assoc ); |
33 | 53 | } |
34 | 54 | } |
35 | | -} |
| 55 | + |
| 56 | +} |
\ No newline at end of file |