public function jsonEncode($data)
    {
        if (is_array($data)) {
            $ret = "";
            $blWasOne = false;
            $blNumerical = true;
            reset($data);
            while ($blNumerical && $key = key($data)) {
                $blNumerical = !is_string($key);
            }
            if ($blNumerical) {
                return '[' . implode(',', array_map([$this, 'jsonEncode'], $data)) . ']';
            } else {
                foreach ($data as $key => $val) {
                    if ($blWasOne) {
                        $ret .= ',';
                    } else {
                        $blWasOne = true;
                    }
                    $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
                }

                return "{" . $ret . "}";
            }
        } else {
            return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
        }
    }