3 use wcf\system\exception\SystemException
;
6 * Provides methods for JSON.
8 * @author Alexander Ebert
9 * @copyright 2001-2014 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package com.woltlab.wcf
13 * @category Community Framework
17 * Returns the JSON representation of a value.
22 public static function encode($data) {
23 return json_encode($data);
27 * Decodes a JSON string.
30 * @param boolean $asArray
33 public static function decode($json, $asArray = true) {
35 $data = json_decode($json, $asArray);
37 if ($data === null && self
::getLastError() !== JSON_ERROR_NONE
) {
38 throw new SystemException('Could not decode JSON (error '.self
::getLastError().'): '.$json);
45 * Returns the last error occurred.
49 public static function getLastError() {
50 return json_last_error();
53 private function __construct() { }