Prado\Web\Javascripts\TJavaScript::jsonEncode PHP Метод

jsonEncode() публичный статический Метод

This method invokes json_encode to perform the encoding.
public static jsonEncode ( $value, $options ) : string
Результат string encoded string
    public static function jsonEncode($value, $options = 0)
    {
        if (($g = Prado::getApplication()->getGlobalization(false)) !== null && strtoupper($enc = $g->getCharset()) != 'UTF-8') {
            self::convertToUtf8($value, $enc);
        }
        $s = @json_encode($value, $options);
        self::checkJsonError();
        return $s;
    }

Usage Example

Пример #1
0
 /**
  * Displays the exceptions to the client-side TJavascriptLogger.
  * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded.
  * @param Exception exception details.
  */
 protected function displayException($exception)
 {
     if ($this->getApplication()->getMode() === TApplication::STATE_DEBUG) {
         $response = $this->getApplication()->getResponse();
         $trace = $this->getExceptionStackTrace($exception);
         // avoid error on non-utf8 strings
         try {
             $trace = TJavaScript::jsonEncode($trace);
         } catch (Exception $e) {
             // strip everythin not 7bit ascii
             $trace = preg_replace('/[^(\\x20-\\x7F)]*/', '', serialize($trace));
         }
         // avoid exception loop if headers have already been sent
         try {
             $response->setStatusCode(500, 'Internal Server Error');
         } catch (Exception $e) {
         }
         $content = $response->createHtmlWriter();
         $content->getWriter()->setBoundary(TActivePageAdapter::CALLBACK_ERROR_HEADER);
         $content->write($trace);
     } else {
         error_log("Error happened while processing an existing error:\n" . $exception->__toString());
         header('HTTP/1.0 500 Internal Server Error', true, 500);
     }
     $this->getApplication()->getResponse()->flush();
 }
All Usage Examples Of Prado\Web\Javascripts\TJavaScript::jsonEncode