当前位置: 首页>>代码示例>>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;未经允许,请勿转载。