当前位置: 首页>>代码示例>>PHP>>正文


PHP Json\Json类代码示例

本文整理汇总了PHP中Zend\Json\Json的典型用法代码示例。如果您正苦于以下问题:PHP Json类的具体用法?PHP Json怎么用?PHP Json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: guardarAction

 public function guardarAction()
 {
     $values = \Zend\Json\Json::decode($this->getRequest()->getContent());
     $content = array();
     foreach ($values as $key) {
         $content[] = $key;
     }
     $nombre = $content[0];
     $session = $content[1];
     $messaggio = $content[2];
     $color = 'yellow';
     $xposition = rand(2, 1000);
     $yposition = rand(3, 650);
     $zposition = rand(1, 100);
     $posiciones = $xposition . 'x' . $yposition . 'x' . $zposition;
     $posterlab = $this->getSessioniDao()->tuttiPerId($session)->getPosterlab();
     $tipo = 1;
     $patron = 'Y-m-d H:i';
     $fecha = new DateTime();
     $fechactual = $fecha->format($patron);
     $stato = 1;
     $productos = array('nome' => $nombre, 'messaggio' => $messaggio, 'color' => $color, 'xyz' => $posiciones, 'posterlab_id' => $posterlab, 'tipo' => $tipo, 'sessione' => $session, 'data' => $fechactual, 'stato' => $stato);
     $producto = new Interattivo();
     $producto->exchangeArray($productos);
     $nuevoid = $this->getInterattivoDao()->salvare($producto);
     //$salvado = $this->getInterattivoDao()->salvare($producto);
     if (!$nuevoid) {
         $json = new JsonModel(array('data' => 'error'));
         return $json;
     } else {
         $json = new JsonModel(array('data' => 'success', 'messaggio' => $messaggio));
         return $json;
     }
 }
开发者ID:sebaxplace,项目名称:skilla-local,代码行数:34,代码来源:IndexController.php

示例2: getResults

 /**
  * @return array
  */
 public function getResults($offset, $itemCountPerPage)
 {
     $query = $this->createSearchQuery($offset, $itemCountPerPage);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('GET');
     $client->setUri($this->getOptions()->getSearchEndpoint() . $query);
     $response = $client->send();
     if (!$response->isSuccess()) {
         throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent());
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $this->count = $results['hits']['found'];
     if (0 == $this->count) {
         return array();
     }
     if ($this->getOptions()->getReturnIdResults()) {
         $results = $this->extractResultsToIdArray($results);
     }
     foreach ($this->getConverters() as $converter) {
         $results = $converter->convert($results);
     }
     return $results;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:29,代码来源:CloudSearchSearcher.php

示例3: render

 /**
  * @param UploaderModelInterface $model
  * @param null $values
  * @return string
  * @throws InvalidArgumentException
  */
 public function render($model, $values = null)
 {
     if (!$model instanceof UploaderModelInterface) {
         throw new InvalidArgumentException("Unsupportable type of model, required type UploaderModelInterface");
     }
     $textArea = new Textarea();
     $textArea->setName('response');
     $textAreaViewHelper = new FormTextarea();
     $jsonEncoder = new Json();
     $value = $jsonEncoder->encode($model->getVariables());
     $textArea->setValue($value);
     return $textAreaViewHelper->render($textArea);
 }
开发者ID:spalax,项目名称:zf2-libs,代码行数:19,代码来源:TextAreaRenderer.php

示例4: onBootstrap

 public function onBootstrap(MvcEvent $event)
 {
     Json::$useBuiltinEncoderDecoder = true;
     $eventManager = $event->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }
开发者ID:aiolos,项目名称:haltes,代码行数:7,代码来源:Module.php

示例5: updateAction

 /**
  * 更新安全密码
  *
  * @author young
  * @name 更新安全密码
  * @version 2014.01.02 young
  * @return JsonModel
  */
 public function updateAction()
 {
     $oldPassword = trim($this->params()->fromPost('oldPassword', ''));
     $password = trim($this->params()->fromPost('password', ''));
     $repeatPassword = trim($this->params()->fromPost('repeatPassword', ''));
     $active = filter_var($this->params()->fromPost('active', ''), FILTER_VALIDATE_BOOLEAN);
     $criteria = array('project_id' => $this->_project_id, 'collection_id' => $this->_collection_id);
     $lockInfo = $this->_lock->findOne($criteria);
     if ($lockInfo != null) {
         if (empty($oldPassword)) {
             return $this->msg(true, '请输入原密码');
         }
         if (sha1($oldPassword) !== $lockInfo['password']) {
             return $this->msg(true, '身份验证未通过');
         }
     }
     if (empty($password) || empty($repeatPassword)) {
         return $this->msg(true, '请输入新密码或者确认密码');
     }
     if ($password !== $repeatPassword) {
         return $this->msg(true, '两次密码输入不一致');
     }
     $datas = array('password' => sha1($password), 'active' => $active);
     if ($active) {
         $rst = $this->_lock->update($criteria, array('$set' => $datas), array('upsert' => true));
         if ($rst['ok']) {
             return $this->msg(true, '设定集合访问密钥成功');
         } else {
             return $this->msg(false, Json::encode($rst));
         }
     } else {
         $this->_lock->remove($criteria);
         return $this->msg(true, '清除安全密钥成功');
     }
 }
开发者ID:im286er,项目名称:ent,代码行数:43,代码来源:LockController.php

示例6: getStorages

 private function getStorages()
 {
     $director = $this->getServiceLocator()->get('director');
     $result = $director->send_command("list storages", 2, null);
     $storages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
     return $storages['result']['storages'];
 }
开发者ID:neverstoplwy,项目名称:bareos-webui,代码行数:7,代码来源:StorageController.php

示例7: direct

    /**
     * Encode data as JSON, disable layouts, and set response header
     *
     * If $keepLayouts is true, does not disable layouts.
     *
     * @param  mixed $data
     * @param  bool $keepLayouts
     * NOTE:   if boolean, establish $keepLayouts to true|false
     *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
     *         this array can contains a 'keepLayout'=>true|false
     *         that will not be passed to Zend_Json::encode method but will be used here
     * @return string|void
     */
    public function direct($data = null, $keepLayouts = false)
    {
        if ($data == null) {
            throw new \InvalidArgumentException('JSON: missing argument. $data is required in json($data, $keepLayouts = false)');
        }
        
        $options = array();
        if (is_array($keepLayouts))
        {
            $options     = $keepLayouts;
            $keepLayouts = (array_key_exists('keepLayouts', $keepLayouts))
                            ? $keepLayouts['keepLayouts']
                            : false;
            unset($options['keepLayouts']);
        }

        $data = \Zend\Json\Json::encode($data, null, $options);
        if (!$keepLayouts) {
            $layout = LayoutManager::getMvcInstance();
            if ($layout instanceof LayoutManager) {
                $layout->disableLayout();
            }
        }

        $response = \Zend\Controller\Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json');
        return $data;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:41,代码来源:Json.php

示例8: testCanSerializeWithJsonpCallback

 public function testCanSerializeWithJsonpCallback()
 {
     $array = array('foo' => 'bar');
     $model = new JsonModel($array);
     $model->setJsonpCallback('callback');
     $this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize());
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:7,代码来源:JsonModelTest.php

示例9: htmlAttribs

 /**
  * Converts an associative array to a string of tag attributes.
  *
  * @access public
  *
  * @param array $attribs From this array, each key-value pair is
  * converted to an attribute name and value.
  *
  * @return string The XHTML for the attributes.
  */
 protected function htmlAttribs($attribs)
 {
     $xhtml = '';
     $escaper = $this->getView()->plugin('escapehtml');
     foreach ((array) $attribs as $key => $val) {
         $key = $escaper($key);
         if ('on' == substr($key, 0, 2) || 'constraints' == $key) {
             // Don't escape event attributes; _do_ substitute double quotes with singles
             if (!is_scalar($val)) {
                 // non-scalar data should be cast to JSON first
                 $val = \Zend\Json\Json::encode($val);
             }
             // Escape single quotes inside event attribute values.
             // This will create html, where the attribute value has
             // single quotes around it, and escaped single quotes or
             // non-escaped double quotes inside of it
             $val = str_replace('\'', ''', $val);
         } else {
             if (is_array($val)) {
                 $val = implode(' ', $val);
             }
             $val = $escaper($val);
         }
         if ('id' == $key) {
             $val = $this->normalizeId($val);
         }
         if (strpos($val, '"') !== false) {
             $xhtml .= " {$key}='{$val}'";
         } else {
             $xhtml .= " {$key}=\"{$val}\"";
         }
     }
     return $xhtml;
 }
开发者ID:mindfeederllc,项目名称:openemr,代码行数:44,代码来源:AbstractHtmlElement.php

示例10: _parseParameters

 protected function _parseParameters(HTTPResponse $response)
 {
     $params = array();
     $body = $response->getBody();
     if (empty($body)) {
         return;
     }
     $tokenFormat = $this->getTokenFormat();
     switch ($tokenFormat) {
         case 'json':
             $params = \Zend\Json\Json::decode($body);
             break;
         case 'jsonp':
             break;
         case 'pair':
             $parts = explode('&', $body);
             foreach ($parts as $kvpair) {
                 $pair = explode('=', $kvpair);
                 $params[rawurldecode($pair[0])] = rawurldecode($pair[1]);
             }
             break;
         default:
             throw new Exception\InvalidArgumentException(sprintf('Unable to handle access token response by undefined format %', $tokenFormat));
     }
     return (array) $params;
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:26,代码来源:AbstractToken.php

示例11: getLatest

    /**
     * Fetches the version of the latest stable release.
     *
     * By Default, this uses the GitHub API (v3) and only returns refs that begin with
     * 'tags/release-'. Because GitHub returns the refs in alphabetical order,
     * we need to reduce the array to a single value, comparing the version
     * numbers with version_compare().
     *
     * If $service is set to VERSION_SERVICE_ZEND this will fall back to calling the
     * classic style of version retreival.
     *
     *
     * @see http://developer.github.com/v3/git/refs/#get-all-references
     * @link https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-
     * @link http://framework.zend.com/api/zf-version?v=2
     * @param string $service Version Service with which to retrieve the version
     * @return string
     */
    public static function getLatest($service = self::VERSION_SERVICE_ZEND)
    {
        if (null === static::$latestVersion) {
            static::$latestVersion = 'not available';
            if ($service == self::VERSION_SERVICE_GITHUB) {
                $url  = 'https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-';

                $apiResponse = Json::decode(file_get_contents($url), Json::TYPE_ARRAY);

                // Simplify the API response into a simple array of version numbers
                $tags = array_map(function ($tag) {
                    return substr($tag['ref'], 18); // Reliable because we're filtering on 'refs/tags/release-'
                }, $apiResponse);

                // Fetch the latest version number from the array
                static::$latestVersion = array_reduce($tags, function ($a, $b) {
                    return version_compare($a, $b, '>') ? $a : $b;
                });
            } elseif ($service == self::VERSION_SERVICE_ZEND) {
                $handle = fopen('http://framework.zend.com/api/zf-version?v=2', 'r');
                if (false !== $handle) {
                    static::$latestVersion = stream_get_contents($handle);
                    fclose($handle);
                }
            }
        }

        return static::$latestVersion;
    }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:47,代码来源:Version.php

示例12: doRequest

 /**
  * @todo whats wrong with SSL?
  * @return array
  */
 public function doRequest()
 {
     $url = 'https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions';
     $client = new Client($url, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE)));
     $client->setMethod(\Zend\Http\Request::METHOD_GET);
     return ZendJson::decode($client->send()->getBody());
 }
开发者ID:schmiddim,项目名称:mvg-live-php,代码行数:11,代码来源:HttpGetInterruptions.php

示例13: listOrdersAction

 public function listOrdersAction()
 {
     $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
     $order = $this->getServiceLocator()->get('TocatCore\\Model\\OrderTableGateway');
     if (empty($params)) {
         return new ViewModel(iterator_to_array($order->select()));
     }
     if (isset($params['ticket_id'])) {
         $rowset = $order->select(function (Select $select) use($params) {
             $select->join('order_ticket', 'order_ticket.order_uid = order.uid', array());
             $select->join('ticket', 'order_ticket.ticket_uid = ticket.uid', array());
             $select->where(array('ticket.ticket_id' => $params['ticket_id']));
             $select->quantifier('DISTINCT');
         });
         return new ViewModel(iterator_to_array($rowset));
     }
     if (isset($params['project_id'])) {
         $rowset = $order->select(function (Select $select) use($params) {
             $select->join('order_project', 'order_project.order_uid = order.uid', array());
             $select->join('project', 'order_project.project_uid = project.uid');
             $select->where(array('project.project_id' => $params['project_id']));
             $select->quantifier('DISTINCT');
         });
         return new ViewModel(iterator_to_array($rowset));
     }
 }
开发者ID:opsway,项目名称:tocat-opsdesk-platform,代码行数:26,代码来源:ListOrdersController.php

示例14: 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

示例15: htmlAttribs

 /**
  * Converts an associative array to a string of tag attributes.
  *
  * @access public
  *
  * @param array $attribs From this array, each key-value pair is
  * converted to an attribute name and value.
  *
  * @return string The XHTML for the attributes.
  */
 protected function htmlAttribs($attribs)
 {
     $xhtml = '';
     $escaper = $this->getView()->plugin('escapehtml');
     $escapeHtmlAttr = $this->getView()->plugin('escapehtmlattr');
     foreach ((array) $attribs as $key => $val) {
         $key = $escaper($key);
         if ('on' == substr($key, 0, 2) || 'constraints' == $key) {
             // Don't escape event attributes; _do_ substitute double quotes with singles
             if (!is_scalar($val)) {
                 // non-scalar data should be cast to JSON first
                 $val = \Zend\Json\Json::encode($val);
             }
         } else {
             if (is_array($val)) {
                 $val = implode(' ', $val);
             }
         }
         $val = $escapeHtmlAttr($val);
         if ('id' == $key) {
             $val = $this->normalizeId($val);
         }
         if (strpos($val, '"') !== false) {
             $xhtml .= " {$key}='{$val}'";
         } else {
             $xhtml .= " {$key}=\"{$val}\"";
         }
     }
     return $xhtml;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:40,代码来源:AbstractHtmlElement.php


注:本文中的Zend\Json\Json类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。