當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Json::prettyPrint方法代碼示例

本文整理匯總了PHP中Zend\Json\Json::prettyPrint方法的典型用法代碼示例。如果您正苦於以下問題:PHP Json::prettyPrint方法的具體用法?PHP Json::prettyPrint怎麽用?PHP Json::prettyPrint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Json\Json的用法示例。


在下文中一共展示了Json::prettyPrint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: render

 /**
  * {@inheritDoc}
  */
 public function render($model, $values = null)
 {
     $apiResponse = $model->getApiResponse();
     if ($apiResponse->isError()) {
         $errors = $apiResponse->getErrors();
         if ($e = $model->getException()) {
             $errors[$apiResponse->getStatus()] = $e->getMessage();
         }
         $payload = ['errors' => $errors];
     } else {
         $payload = $apiResponse->getContent();
     }
     if (null === $payload) {
         return null;
     }
     $jsonpCallback = $model->getOption('callback');
     if (null !== $jsonpCallback) {
         // Wrap the JSON in a JSONP callback.
         $this->setJsonpCallback($jsonpCallback);
     }
     $output = parent::render($payload);
     if (null !== $model->getOption('pretty_print')) {
         // Pretty print the JSON.
         $output = Json::prettyPrint($output);
     }
     return $output;
 }
開發者ID:patrova,項目名稱:omeka-s,代碼行數:30,代碼來源:ApiJsonRenderer.php

示例2: argsAction

 public function argsAction()
 {
     $job = $this->api()->read('jobs', $this->params('id'))->getContent();
     $args = Json::prettyPrint(Json::encode($job->args()), ['indent' => '  ']);
     $response = $this->getResponse();
     $response->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=utf-8');
     $response->setContent($args);
     return $response;
 }
開發者ID:patrova,項目名稱:omeka-s,代碼行數:9,代碼來源:JobController.php

示例3: uploadString

 /**
  * Writes log message to file
  * @param $name
  * @param $content
  * @param string $contentType
  * @return string
  */
 public function uploadString($name, $content, $contentType = 'text/plain')
 {
     $fileName = $this->path . '/' . $this->getFilePathAndUniquePrefix() . $name;
     if ($contentType === 'application/json') {
         $content = Json::prettyPrint($content);
     }
     (new Filesystem())->dumpFile($fileName, $content);
     return $fileName;
 }
開發者ID:keboola,項目名稱:debug-log-uploader,代碼行數:16,代碼來源:UploaderFile.php

示例4: Encode

 /**
  * Encode any mixed-type value into JSON
  *
  * @param mixed $value          Value to be encoded to JSON
  * @param boolean $prettify     [optional] If JSON should be prettify-formatted
  * @param boolean $html         [optional] If spaces/indents should be properly viewable for HTML
  * @return string
  */
 public static function Encode($value, $prettify = false, $html = false)
 {
     $json = ZendJson::encode($value);
     if ($prettify) {
         $json = ZendJson::prettyPrint($json);
         if ($html) {
             $json = str_replace("\n", '<br>', str_replace(' ', '&nbsp;', $json));
         }
     }
     return $json;
 }
開發者ID:allenlinatoc,項目名稱:quickstart,代碼行數:19,代碼來源:JSON.php

示例5: index01Action

 public function index01Action()
 {
     $input = array('invokables' => array('Data\\Controller\\Index' => 'Data\\Controller\\IndexController', 'Data\\Controller\\Filter' => 'Data\\Controller\\FilterController', 'Data\\Controller\\Serializer' => 'Data\\Controller\\SerializerController', 'Data\\Controller\\Escaper' => 'Data\\Controller\\EscaperController', 'Data\\Controller\\Purifier' => 'Data\\Controller\\PurifierController', 'Data\\Controller\\Dom' => 'Data\\Controller\\DomController', 'Data\\Controller\\Json' => 'Data\\Controller\\JsonController'));
     $output = \Zend\Json\Json::encode($input);
     $strJson = \Zend\Json\Json::encode($input);
     echo \Zend\Json\Json::prettyPrint($output, array("indent" => "\t")) . '<br/>';
     //$o = \Zend\Json\Json::decode($strJson); /** chuyển về 1 đối tượng object */
     $o = \Zend\Json\Json::decode($strJson, \Zend\Json\Json::TYPE_ARRAY);
     /** chuyển về 1 array */
     echo '<pre>';
     print_r($o);
     echo '</pre>';
     return $this->response;
 }
開發者ID:htam261,項目名稱:zendskeleton,代碼行數:14,代碼來源:JsonController.php

示例6: generate

 public static function generate(array $config, $profilePath = null)
 {
     $buildConfig = $config['build'];
     $packages = array();
     foreach ($buildConfig['packages'] as $name => $path) {
         $packages[] = array('name' => $name, 'location' => $path);
     }
     $profile = $buildConfig;
     unset($profile['profilePath']);
     $profile['packages'] = $packages;
     $profile = Json::prettyPrint(Json::encode($profile));
     $profile = str_replace('<profile>', $profile, file_get_contents(__DIR__ . '/Profile.js.template'));
     if (!isset($profilePath)) {
         $profilePath = $buildConfig['profilePath'];
     }
     if (file_put_contents($profilePath, $profile)) {
         return array($profile, $profilePath);
     } else {
         return array(null, $profilePath);
     }
 }
開發者ID:ronald132,項目名稱:dojoModule,代碼行數:21,代碼來源:ProfileGenerator.php

示例7: testGetResources

 public function testGetResources()
 {
     $response = ClientStatic::get(self::HOST . '/resources', [], ['Accept' => 'application/hal+json']);
     echo Json::prettyPrint($response->getBody());
 }
開發者ID:zfegg,項目名稱:zfegg-admin,代碼行數:5,代碼來源:test-resource.php

示例8: render

    /**
     * Render a Zend_Config into a JSON config string.
     *
     * @since 1.10
     * @return string
     */
    public function render()
    {
        $data        = $this->_config->toArray();
        $sectionName = $this->_config->getSectionName();
        $extends     = $this->_config->getExtends();

        if (is_string($sectionName)) {
            $data = array($sectionName => $data);
        }

        foreach ($extends as $section => $parentSection) {
            $data[$section][JsonConfig::EXTENDS_NAME] = $parentSection;
        }

        // Ensure that each "extends" section actually exists
        foreach ($data as $section => $sectionData) {
            if (is_array($sectionData) && isset($sectionData[JsonConfig::EXTENDS_NAME])) {
                $sectionExtends = $sectionData[JsonConfig::EXTENDS_NAME];
                if (!isset($data[$sectionExtends])) {
                    // Remove "extends" declaration if section does not exist
                    unset($data[$section][JsonConfig::EXTENDS_NAME]);
                }
            }
        }

        $out = JsonUtil::encode($data);
        if ($this->prettyPrint()) {
             $out = JsonUtil::prettyPrint($out);
        }
        return $out;
    }
開發者ID:ruflin,項目名稱:zf2,代碼行數:37,代碼來源:Json.php

示例9: __invoke

 /**
  * Invoked by event manager
  *
  * @param  MvcEvent $e
  * @return void
  */
 public function __invoke(MvcEvent $e)
 {
     $response = $e->getResponse();
     $headers = $response->getHeaders();
     if (!$headers->has('Content-Type')) {
         return;
     }
     $contentType = $headers->get('Content-Type');
     if (false !== strpos('application/json', $contentType->getFieldValue())) {
         return;
     }
     $request = $e->getRequest();
     $headers = $request->getHeaders();
     if (!$headers->has('X-Pretty-Json')) {
         return;
     }
     $body = $response->getContent();
     $body = Json::prettyPrint($body, array('indent' => '  '));
     $body = $body . "\n";
     $response->setContent($body);
 }
開發者ID:soflomo,項目名稱:common,代碼行數:27,代碼來源:PrettyPrintJsonListener.php

示例10: compileAction

 /**
  * Compile bootstrap for a theme
  */
 public function compileAction()
 {
     // Theme name
     $name = _post('name') ?: Pi::theme()->current();
     // Compiled boostrap.min.css, string
     $bsString = _post('less');
     // Config JSON string
     $cfgString = _post('custom');
     // Write bootstrap scripts to online custom theme folder
     $path = sprintf('%s/custom/theme/%s/asset/vendor/bootstrap/css', Pi::path('asset'), $name);
     $configJson = Json::prettyPrint(json_encode($cfgString), array('indent' => '  '));
     Pi::service('file')->mkdir($path);
     file_put_contents($path . '/bootstrap.min.css', $bsString);
     file_put_contents(dirname($path) . '/config.json', $configJson);
     // Republish the theme
     Pi::service('asset')->publishTheme($name);
     return array('status' => 1, 'message' => __('Bootstrap compiled successfully.'));
 }
開發者ID:Andyyang1981,項目名稱:pi,代碼行數:21,代碼來源:ThemeController.php

示例11: serialize

 public function serialize()
 {
     $json = parent::serialize();
     return \Zend\Json\Json::prettyPrint($json, array('indent' => '    '));
 }
開發者ID:ivan-novakov,項目名稱:php-in-general,代碼行數:5,代碼來源:DebugJsonModel.php

示例12: array

<?php

use Zend\Json\Json;
use Zend\Json\Decode;
require_once '/home/matthew/tmp/composer/vendor/autoload.php';
$json = file_get_contents('users.search.raw.json');
$php = Json::decode($json);
$json = Json::encode($php);
$json = Json::prettyPrint($json, array('indent' => '  '));
echo $json;
開發者ID:emus,項目名稱:php-zend2-old,代碼行數:10,代碼來源:normalize_json.php

示例13: testPrettyPrintDoublequoteFollowingEscapedBackslashShouldNotBeTreatedAsEscaped

 public function testPrettyPrintDoublequoteFollowingEscapedBackslashShouldNotBeTreatedAsEscaped()
 {
     $this->assertEquals("[\n\t1,\n\t\"\\\\\",\n\t3\n]", Json\Json::prettyPrint(Json\Json::encode(array(1, '\\', 3))));
     $this->assertEquals("{\n\t\"a\":\"\\\\\"\n}", Json\Json::prettyPrint(Json\Json::encode(array('a' => '\\'))));
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:5,代碼來源:JsonTest.php

示例14: JsonForm

<?php

use JzForm\Render\Json\Form as JsonForm;
require_once 'autoloader.php';
$form = (require 'forms/simple.php');
$filter = (require 'filters/simple.php');
$render = new JsonForm();
$json = $render->render($form, $filter);
$string = \Zend\Json\Json::encode($json);
echo \Zend\Json\Json::prettyPrint($string);
開發者ID:rb-cohen,項目名稱:jzform,代碼行數:10,代碼來源:simple.php

示例15: formatAttributes

 /**
  * {@inheritdoc}
  */
 public function formatAttributes(array $attributes = [])
 {
     $json = Json::encode($attributes, false, ['enableJsonExprFinder' => true]);
     $content = Json::prettyPrint($json, ['indent' => '    ']);
     return $content;
 }
開發者ID:Newman101,項目名稱:WellCommerce,代碼行數:9,代碼來源:JavascriptFormatter.php


注:本文中的Zend\Json\Json::prettyPrint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。