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


PHP Json::decode方法代码示例

本文整理汇总了PHP中Json::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::decode方法的具体用法?PHP Json::decode怎么用?PHP Json::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Json的用法示例。


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

示例1: load

 public static function load($path)
 {
     if (!is_readable($path)) {
         return [];
     }
     $json = file_get_contents($path);
     return Json::decode($json);
 }
开发者ID:arter97,项目名称:h5ai,代码行数:8,代码来源:class-json.php

示例2: doDefault

 /**
  * 显示登录页(默认Action)
  */
 function doDefault()
 {
     $data = array('a', 'b' => 'roast');
     $json = new Json();
     $str_encoded = $json->encode($data);
     var_dump($str_encoded);
     var_dump($json->decode($str_encoded));
 }
开发者ID:sanplit,项目名称:huishou,代码行数:11,代码来源:utiljson.php

示例3: loadMessagesFromFile

 /**
  * Loads the message translation for the specified language and category.
  * @param string $messageFile string The path to message file.
  * @return string[] The message array, or an empty array if the file is not found or invalid.
  */
 protected function loadMessagesFromFile($messageFile) : array
 {
     if (!is_file($messageFile)) {
         return [];
     }
     $messages = Json::decode(@file_get_contents($messageFile));
     return is_array($messages) ? $messages : [];
 }
开发者ID:cedx,项目名称:yii2-json-messages,代码行数:13,代码来源:JsonMessageSource.php

示例4: testDecode_WithError

 /**
  * Tests the <code>decode()</code> method with an exception.
  *
  * @covers Braincrafted\Json\Json::decode()
  * @covers Braincrafted\Json\Json::getError()
  */
 public function testDecode_WithError()
 {
     try {
         Json::decode('{"var1":"foo","var2":42');
         $this->assertTrue(false);
     } catch (JsonDecodeException $e) {
         $this->assertTrue(true);
     }
 }
开发者ID:braincrafted,项目名称:json,代码行数:15,代码来源:JsonTest.php

示例5: getCampaigns

 /**
  *
  * @return CompanyEntity
  */
 public function getCampaigns()
 {
     $request = Request::get("{$this->getCompanyId()}/campaigns");
     $response = $this->getConnector()->sendRequest($request);
     $data = Json::decode($response->getContent());
     $json = new stdClass();
     $json->campaigns = $data;
     return new CampaignsEntity($json);
 }
开发者ID:QuantiCZ,项目名称:MailQ-PHP-Library,代码行数:13,代码来源:CampaignResource.php

示例6: getUnsubscribersByEmail

 /**
  * 
  * @param string $email
  * @return UnsubscribersEntity
  */
 public function getUnsubscribersByEmail($email)
 {
     $request = Request::get("{$this->getCompanyId()}/unsubscribers/{$email}");
     $response = $this->getConnector()->sendRequest($request);
     $data = Json::decode($response->getContent());
     $json = new stdClass();
     $json->unsubscribers = $data;
     return new UnsubscribersEntity($json);
 }
开发者ID:QuantiCZ,项目名称:MailQ-PHP-Library,代码行数:14,代码来源:UnsubscriberResource.php

示例7: parseFunction

 /**
  * Parses custom function calls for geting function name and parameters.
  *
  * @param string $function
  *
  * @return array
  */
 private function parseFunction($function)
 {
     if (!Str::contains($function, ':')) {
         return [$function, []];
     }
     list($function, $params) = explode(':', $function, 2);
     $params = (array) Json::decode($params, true);
     return [$function, $params];
 }
开发者ID:elegantweb,项目名称:framework,代码行数:16,代码来源:FunctionParserTrait.php

示例8: testEncodeAndDecode

 public function testEncodeAndDecode()
 {
     $value = 1;
     $this->assertEquals($value, Json::decode(Json::encode($value)));
     $value = 'foo';
     $this->assertEquals($value, Json::decode(Json::encode($value)));
     $value = ['foo' => 'bar'];
     $this->assertEquals($value, Json::decode(Json::encode($value)));
     $value = ['foo', 'bar'];
     $this->assertEquals($value, Json::decode(Json::encode($value)));
 }
开发者ID:jivoo,项目名称:core,代码行数:11,代码来源:JsonTest.php

示例9: update

 public function update()
 {
     $data = Json::decode(Request::post('data'));
     $id = Request::post('id', true, Validator::INT);
     if (!$data) {
         throw new ValidatorException('Некорректный параметр data');
     }
     //проверка данных
     $this->validateDataForSave($data);
     echo $this->_update($data, $id);
 }
开发者ID:pavel78779,项目名称:my_cms,代码行数:11,代码来源:ContentManager.php

示例10: parseArguments

 /**
  * Parses the arguments of a parametrized helper.
  * Arguments can be specified as a single value, or as a string in JSON format.
  * @param string $text The section content specifying the helper arguments.
  * @param string $defaultArgument The name of the default argument. This is used when the section content provides a plain string instead of a JSON object.
  * @param array $defaultValues The default values of arguments. These are used when the section content does not specify all arguments.
  * @return array The parsed arguments as an associative array.
  */
 protected function parseArguments(string $text, string $defaultArgument, array $defaultValues = []) : array
 {
     try {
         if (is_array($json = Json::decode($text))) {
             return ArrayHelper::merge($defaultValues, $json);
         }
         throw new InvalidParamException();
     } catch (InvalidParamException $e) {
         $defaultValues[$defaultArgument] = $text;
         return $defaultValues;
     }
 }
开发者ID:cedx,项目名称:yii2-mustache,代码行数:20,代码来源:Helper.php

示例11: index

 /**
  * ControllerStyleTemplate::index()
  * 
  * @see Load
  * @see Document
  * @see Language
  * @see getList
  * @return void
  */
 public function index()
 {
     $this->load->auto('json');
     $response = Json::decode($this->fetchUrl('http://www.necotienda.org/api/index.php?r=style/template/get'));
     if ($response['response_code'] === 200) {
         $this->data['templates'] = $response['data']['data'];
     }
     $this->template = 'style/template_list.tpl';
     $this->children[] = 'common/header';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
开发者ID:josueaponte7,项目名称:necotienda_standalone,代码行数:22,代码来源:template.php

示例12: add

 public function add()
 {
     $data = Json::decode(Request::post('data'));
     if (empty($data['type'])) {
         throw new ValidatorException('Параметр "type" не передан или пустой');
     }
     $real_url = eval($this->db->getOne('SELECT `url_maker` FROM ##items_types WHERE `id`=?i LIMIT 1', [$data['type']])) . '.html';
     $data['params'] = Json::encode($data['item_params']);
     unset($data['item_params']);
     $id = parent::_add($data);
     $this->db->query("INSERT INTO ##url_redirects (`old_url`,`new_url`,`type`,`system`,`comment`) VALUES (?s,?s,'I',1,?i)", [$data['item_url'], $real_url, $id]);
     echo $id;
 }
开发者ID:pavel78779,项目名称:my_cms,代码行数:13,代码来源:MenuItemsManager.php

示例13: parse

 /**
  * @param string $json
  *
  * @throws Exception\JsonParseException
  *
  * @return Request|Request[]
  */
 public function parse($json)
 {
     // decode the string
     $request = Json::decode($json, $this->jsonDecodeDepthLimit);
     // create a new collection
     if (is_array($request) && count($request) > 0) {
         // non-empty arrays are attempts at batch requests
         $collection = array();
         foreach ($request as $singleRequest) {
             $collection[] = $this->createFrom($singleRequest);
         }
         return $collection;
     } else {
         // all other valid json is treated as a single request
         return $this->createFrom($request);
     }
 }
开发者ID:nathan-muir,项目名称:json-rpc-2,代码行数:24,代码来源:RequestParser.php

示例14: unserialize

 /**
  * @param mixed $value
  * @param bool $throwException
  * @throws SerializeException
  * @return mixed
  */
 public static function unserialize($value, $throwException = true)
 {
     if ($throwException === false) {
         if (!is_string($value)) {
             return $value;
         }
     }
     if (static::is($value)) {
         return unserialize($value);
     } elseif (Json::is($value)) {
         return Json::decode($value);
     }
     if ($throwException == true) {
         throw new SerializeException(SerializeException::NOT_SERIALIZE);
     }
     return $value;
 }
开发者ID:romeoz,项目名称:rock-helpers,代码行数:23,代码来源:Serialize.php

示例15: geocode

 static function geocode($place, $country = '')
 {
     $text = $country ? $place . ',' . $country : $place;
     $temp = TempStore::getInstance();
     $key = 'YahooQueryClient/geocode//' . $text;
     $data = $temp->get($key);
     if ($data) {
         return unserialize($data);
     }
     $q = urlencode('select * from geo.places where text="' . $text . '"');
     $url = 'http://query.yahooapis.com/v1/public/yql?q=' . $q . '&format=json';
     $x = Json::decode($url);
     //XXX: instead return all results as array of YahooGeocodeResult objects?
     if ($x->query->count > 1) {
         $item = $x->query->results->place[0];
     } else {
         $item = $x->query->results->place;
     }
     $res = new YahooGeocodeResult();
     $res->name = $item->name;
     $res->country = $item->country->code;
     /* XXX TODO: parse admin1, admin2:
     
     admin1: {
         * code: ""
         * type: "County"
         * content: "Jamtland"
     }
     admin2: {
         * code: ""
         * type: "Municipality"
         * content: "Härjedalen"
     }
     */
     $res->woeid = $item->woeid;
     $res->area = new \StdClass();
     $res->area->center = new YahooQueryCoordinate($item->centroid->latitude, $item->centroid->longitude);
     $res->area->sw = new YahooQueryCoordinate($item->boundingBox->southWest->latitude, $item->boundingBox->southWest->longitude);
     $res->area->ne = new YahooQueryCoordinate($item->boundingBox->northEast->latitude, $item->boundingBox->northEast->longitude);
     //XXX this is a ugly hack until yahoo returns timezone with their response
     $geoname = GeonamesClient::reverse($item->centroid->latitude, $item->centroid->longitude);
     $res->timezone = $geoname->timezone;
     $temp->set($key, serialize($res));
     return $res;
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:45,代码来源:YahooQueryClient.php


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