本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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(' ', ' ', $json));
}
}
return $json;
}
示例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;
}
示例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);
}
}
示例7: testGetResources
public function testGetResources()
{
$response = ClientStatic::get(self::HOST . '/resources', [], ['Accept' => 'application/hal+json']);
echo Json::prettyPrint($response->getBody());
}
示例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;
}
示例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);
}
示例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.'));
}
示例11: serialize
public function serialize()
{
$json = parent::serialize();
return \Zend\Json\Json::prettyPrint($json, array('indent' => ' '));
}
示例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;
示例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' => '\\'))));
}
示例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);
示例15: formatAttributes
/**
* {@inheritdoc}
*/
public function formatAttributes(array $attributes = [])
{
$json = Json::encode($attributes, false, ['enableJsonExprFinder' => true]);
$content = Json::prettyPrint($json, ['indent' => ' ']);
return $content;
}