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


PHP Helpers::jsonEncode方法代碼示例

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


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

示例1: createRequest

 /**
  * @param  string  Http\Request::GET|POST|...
  * @param  string  path like '/users/:user/repos' where ':user' is substitution
  * @param  array[name => value]  replaces substitutions in $urlPath, the rest is appended as query string to URL
  * @param  array[name => value]  name is case-insensitive
  * @param  mixed|NULL  arrays and objects are encoded to JSON and Content-Type is set
  * @return Http\Request
  *
  * @throws MissingParameterException  when substitution is used in URL but parameter is missing
  * @throws JsonException  when encoding to JSON fails
  */
 public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
 {
     $parameters += $this->defaultParameters;
     $this->substituteUrlParameters($urlPath, $parameters);
     $url = rtrim($this->url, '/') . '/' . trim($urlPath, '/');
     if (count($parameters)) {
         $url .= '?' . http_build_query($parameters);
     }
     if ($content !== NULL && (is_array($content) || is_object($content))) {
         $headers['Content-Type'] = 'application/json; charset=utf-8';
         $content = Helpers::jsonEncode($content);
     }
     return new Http\Request($method, $url, $headers, $content);
 }
開發者ID:ElvenSpellmaker,項目名稱:github-api,代碼行數:25,代碼來源:Api.php

示例2: createRequest

 /**
  * @param  string  Http\Request::GET|POST|...
  * @param  string  path like '/users/:user/repos' where ':user' is substitution
  * @param  array[name => value]  replaces substitutions in $urlPath, the rest is appended as query string to URL
  * @param  array[name => value]  name is case-insensitive
  * @param  mixed|NULL  arrays and objects are encoded to JSON and Content-Type is set
  * @return Http\Request
  *
  * @throws MissingParameterException  when substitution is used in URL but parameter is missing
  * @throws JsonException  when encoding to JSON fails
  */
 public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
 {
     if (stripos($urlPath, $this->url) === 0) {
         $urlPath = substr($urlPath, strlen($this->url));
     }
     if (strpos($urlPath, '{') === FALSE) {
         $urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters);
     } else {
         $urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters);
     }
     $url = rtrim($this->url, '/') . '/' . ltrim($urlPath, '/');
     if ($content !== NULL && (is_array($content) || is_object($content))) {
         $headers['Content-Type'] = 'application/json; charset=utf-8';
         $content = Helpers::jsonEncode($content);
     }
     return new Http\Request($method, $url, $headers, $content);
 }
開發者ID:runt18,項目名稱:github-api-1,代碼行數:28,代碼來源:Api.php

示例3: processRequestOutput_json

 protected function processRequestOutput_json(array $_)
 {
     return Helpers::jsonEncode($_["result"], 500);
 }
開發者ID:keradus,項目名稱:ker,代碼行數:4,代碼來源:Server.php

示例4: createRequest

 /**
  * @param  string  Http\Request::GET|POST|...
  * @param  string  path like '/users/:user/repos' where ':user' is substitution
  * @param  array[name => value]  replaces substitutions in $urlPath, the rest is appended as query string to URL
  * @param  array[name => value]  name is case-insensitive
  * @param  mixed|NULL  arrays and objects are encoded to JSON and Content-Type is set
  * @return Http\Request
  *
  * @throws MissingParameterException  when substitution is used in URL but parameter is missing
  * @throws JsonException  when encoding to JSON fails
  */
 public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
 {
     if (stripos($urlPath, $this->url) === 0) {
         # Allows non-HTTPS URLs
         $baseUrl = $this->url;
         $urlPath = substr($urlPath, strlen($this->url));
     } elseif (preg_match('#^(https://[^/]+)(/.*)?$#', $urlPath, $m)) {
         $baseUrl = $m[1];
         $urlPath = isset($m[2]) ? $m[2] : '';
     } else {
         $baseUrl = $this->url;
     }
     if (strpos($urlPath, '{') === FALSE) {
         $urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters);
     } else {
         $urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters);
     }
     $url = rtrim($baseUrl, '/') . '/' . ltrim($urlPath, '/');
     if ($content !== NULL && (is_array($content) || is_object($content))) {
         $headers['Content-Type'] = 'application/json; charset=utf-8';
         $content = Helpers::jsonEncode($content);
     }
     return new Http\Request($method, $url, $headers, $content);
 }
開發者ID:milo,項目名稱:github-api,代碼行數:35,代碼來源:Api.php

示例5: sendRequest_encodeData_json

 public function sendRequest_encodeData_json(array $_)
 {
     return Helpers::jsonEncode($_);
 }
開發者ID:keradus,項目名稱:ker,代碼行數:4,代碼來源:Client.php


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