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


PHP Json::decode方法代码示例

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


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

示例1: authenticate

 /**
  * @param $username
  * @param $password
  * @return array Success {
  *  @var string AccessId
  *  @var string SecretKey
  *  @var string UserId
  *  @var string EmployeeId
  * }
  * @throws MPAuthException
  */
 public function authenticate($username, $password)
 {
     $data = ['Login' => $username, 'Password' => md5($password)];
     $this->prepareRequest($data);
     try {
         $response = $this->curl->post($this->url . $this->authRelativeUrl, true);
         try {
             $decodedResponse = Json::decode($response, true);
             switch ($decodedResponse['status']['code']) {
                 case 'ok':
                     break;
                 case 'error':
                     throw new MPAuthException('Invalid username or password.');
                     break;
                 default:
                     throw new MPAuthException('Unknown response status.');
             }
             return $decodedResponse['data'];
         } catch (InvalidParamException $e) {
             throw new MPAuthException('Error decoding server response. Raw response: ' . var_export($response, true));
         }
     } catch (Exception $e) {
         throw new MPAuthException('Error requesting host:' . $e->getMessage() . $e->getCode());
     }
 }
开发者ID:leammas,项目名称:yii2-megaplanauth,代码行数:36,代码来源:MegaplanAuth.php

示例2: callback

 public function callback(AMQPMessage $msg)
 {
     $routingKey = $msg->get('routing_key');
     $method = 'read' . Inflector::camelize($routingKey);
     $interpreter = isset($this->interpreters[$this->exchange]) ? $this->interpreters[$this->exchange] : (isset($this->interpreters['*']) ? $this->interpreters['*'] : null);
     if ($interpreter === null) {
         $interpreter = $this;
     } else {
         if (class_exists($interpreter)) {
             $interpreter = new $interpreter();
             if (!$interpreter instanceof AmqpInterpreter) {
                 throw new Exception(sprintf("Class '%s' is not correct interpreter class.", $interpreter));
             }
         } else {
             throw new Exception(sprintf("Interpreter class '%s' was not found.", $interpreter));
         }
     }
     if (method_exists($interpreter, $method) || is_callable([$interpreter, $method])) {
         $info = ['exchange' => $this->exchange, 'routing_key' => $routingKey, 'reply_to' => $msg->has('reply_to') ? $msg->get('reply_to') : null, 'delivery_tag' => $msg->get('delivery_tag')];
         try {
             $body = Json::decode($msg->body, true);
         } catch (\Exception $e) {
             $body = $msg->body;
         }
         $interpreter->{$method}($body, $info, $this->amqp->channel);
     } else {
         if (!$interpreter instanceof AmqpInterpreter) {
             $interpreter = new AmqpInterpreter();
         }
         $interpreter->log(sprintf("Unknown routing key '%s' for exchange '%s'.", $routingKey, $this->exchange), $interpreter::MESSAGE_ERROR);
         // debug the message
         $interpreter->log(print_r(Json::decode($msg->body, true), true), $interpreter::MESSAGE_INFO);
     }
 }
开发者ID:vstaheev,项目名称:yii2-amqp,代码行数:34,代码来源:AmqpListenerController.php

示例3: callback

 public function callback(AMQPMessage $msg)
 {
     $routingKey = $msg->delivery_info['routing_key'];
     $method = 'read' . Inflector::camelize($routingKey);
     if (!isset($this->interpreters[$this->exchange])) {
         $interpreter = $this;
     } elseif (class_exists($this->interpreters[$this->exchange])) {
         $interpreter = new $this->interpreters[$this->exchange]();
         if (!$interpreter instanceof AmqpInterpreter) {
             throw new Exception(sprintf("Class '%s' is not correct interpreter class.", $this->interpreters[$this->exchange]));
         }
     } else {
         throw new Exception(sprintf("Interpreter class '%s' was not found.", $this->interpreters[$this->exchange]));
     }
     if (method_exists($interpreter, $method)) {
         $info = ['exchange' => $msg->get('exchange'), 'routing_key' => $msg->get('routing_key'), 'reply_to' => $msg->has('reply_to') ? $msg->get('reply_to') : null];
         $interpreter->{$method}(Json::decode($msg->body, true), $info);
     } else {
         if (!isset($this->interpreters[$this->exchange])) {
             $interpreter = new AmqpInterpreter();
         }
         $interpreter->log(sprintf("Unknown routing key '%s' for exchange '%s'.", $routingKey, $this->exchange), $interpreter::MESSAGE_ERROR);
         // debug the message
         $interpreter->log(print_r(Json::decode($msg->body, true), true), $interpreter::MESSAGE_INFO);
     }
 }
开发者ID:LexxanderDream,项目名称:yii2-amqp,代码行数:26,代码来源:AmqpListenerController.php

示例4: actionDownload

 /**
  * Download the exported file
  *
  * @return mixed
  */
 public function actionDownload()
 {
     $request = Yii::$app->request;
     $type = $request->post('export_filetype', 'html');
     $name = $request->post('export_filename', Yii::t('kvgrid', 'export'));
     $content = $request->post('export_content', Yii::t('kvgrid', 'No data found'));
     $mime = $request->post('export_mime', 'text/plain');
     $encoding = $request->post('export_encoding', 'utf-8');
     $bom = $request->post('export_bom', true);
     $config = $request->post('export_config', '{}');
     if ($type == GridView::PDF) {
         $config = Json::decode($config);
         $this->generatePDF($content, "{$name}.pdf", $config);
         /** @noinspection PhpInconsistentReturnPointsInspection */
         return;
     } elseif ($type == GridView::HTML) {
         $content = HtmlPurifier::process($content);
     } elseif ($type == GridView::CSV || $type == GridView::TEXT) {
         if ($encoding != 'utf-8') {
             $content = mb_convert_encoding($content, $encoding, 'utf-8');
         } elseif ($bom) {
             $content = chr(239) . chr(187) . chr(191) . $content;
             // add BOM
         }
     }
     $this->setHttpHeaders($type, $name, $mime, $encoding);
     return $content;
 }
开发者ID:kartik-v,项目名称:yii2-grid,代码行数:33,代码来源:ExportController.php

示例5: actionLog

 public function actionLog()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $data = \yii\helpers\Json::decode(\Yii::$app->request->post('data'));
     $entry = null;
     if (isset($data['auditEntry'])) {
         $entry = models\AuditEntry::findOne($data['auditEntry']);
     } else {
         return ['result' => 'error', 'message' => 'No audit entry to attach to'];
     }
     // Convert data into the loggable object
     $javascript = new models\AuditJavascript();
     $map = ['auditEntry' => 'audit_id', 'message' => 'message', 'type' => 'type', 'file' => 'origin', 'line' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'col' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'data' => function ($value) use($javascript) {
         if (count($value)) {
             $javascript->data = $value;
         }
     }];
     foreach ($map as $key => $target) {
         if (isset($data[$key])) {
             if (is_callable($target)) {
                 $target($data[$key]);
             } else {
                 $javascript->{$target} = $data[$key];
             }
         }
     }
     if ($javascript->save()) {
         return ['result' => 'ok'];
     }
     return ['result' => 'error', 'errors' => $javascript->getErrors()];
 }
开发者ID:cornernote,项目名称:yii2-audit,代码行数:35,代码来源:JavascriptController.php

示例6: resetPassword

 /**
  * Resets password.
  * @return boolean if password was reset
  */
 public function resetPassword()
 {
     $bag = Yii::$app->request->get();
     $url = Yii::$app->params['api_url'] . '/clientSetPassword?' . http_build_query(['client' => $bag['login'], 'new_password' => $this->password, 'confirm_data' => $bag]);
     $res = Json::decode(file_get_contents($url));
     return !isset($res['_error']);
 }
开发者ID:hiqdev,项目名称:hiam-core,代码行数:11,代码来源:ResetPasswordForm.php

示例7: decode

 public static function decode($json, $asArray = true, $isQuoted = true)
 {
     if (!$isQuoted) {
         $json = "{\"" . str_replace(array(":", ","), array("\":\"", "\",\""), $json) . "\"}";
     }
     return parent::decode($json, $asArray);
 }
开发者ID:pafnow,项目名称:yii2-helpers,代码行数:7,代码来源:Json.php

示例8: getArticles

 public function getArticles()
 {
     if (!($articles = $this->getAttribute('articles'))) {
         return [];
     }
     return Json::decode($articles);
 }
开发者ID:BoBRoID,项目名称:new.k-z,代码行数:7,代码来源:MainTheme.php

示例9: runAction

 /**
  * Validates, runs Action and returns result in JSON-RPC 2.0 format
  * @param string $id the ID of the action to be executed.
  * @param array $params the parameters (name-value pairs) to be passed to the action.
  * @throws \Exception
  * @throws \yii\web\HttpException
  * @return mixed the result of the action.
  * @see createAction()
  */
 public function runAction($id, $params = [])
 {
     $this->initRequest($id);
     try {
         $requestObject = Json::decode(file_get_contents('php://input'), false);
     } catch (InvalidParamException $e) {
         $requestObject = null;
     }
     $isBatch = is_array($requestObject);
     $requests = $isBatch ? $requestObject : [$requestObject];
     $resultData = null;
     if (empty($requests)) {
         $isBatch = false;
         $resultData = [Helper::formatResponse(null, new Exception("Invalid Request", Exception::INVALID_REQUEST))];
     } else {
         foreach ($requests as $request) {
             if ($response = $this->getActionResponse($request)) {
                 $resultData[] = $response;
             }
         }
     }
     $response = Yii::$app->getResponse();
     $response->format = Response::FORMAT_JSON;
     $response->data = $isBatch || null === $resultData ? $resultData : current($resultData);
     return $response;
 }
开发者ID:cranetm,项目名称:yii2-json-rpc-2.0,代码行数:35,代码来源:Controller.php

示例10: init

 public function init()
 {
     self::$modelSetting = new GoogleFeed();
     self::$modelSetting->loadConfig();
     $this->handlers = Json::decode(self::$modelSetting->feed_handlers);
     foreach ($this->handlers as $handler) {
         if (is_subclass_of($handler, ModificationDataInterface::class)) {
             $this->on(self::MODIFICATION_DATA, [$handler, 'processData']);
         }
     }
     parent::init();
     if ($this->mainCurrency === null) {
         $this->mainCurrency = Currency::findOne(['iso_code' => self::$modelSetting->shop_main_currency]);
     }
     if ($this->host === null) {
         $this->host = self::$modelSetting->shop_host;
     }
     if ($this->title === null) {
         $this->title = self::$modelSetting->shop_name;
     }
     if ($this->description === null) {
         $this->description = self::$modelSetting->shop_description;
     }
     if ($this->fileName === null) {
         $this->fileName = self::$modelSetting->feed_file_name;
     }
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:27,代码来源:GoogleMerchants.php

示例11: json_post

 public function json_post($uri, array $options = [])
 {
     $res = $this->client->request('POST', $uri, $options);
     $body = $res->getBody();
     $json = Json::decode($body);
     return $json;
 }
开发者ID:didwjdgks,项目名称:kepco,代码行数:7,代码来源:Http.php

示例12: processProductInfoData

 private function processProductInfoData($header, $filePath, $classFunction, $params = [])
 {
     LogUtil::info(['message' => 'Begin to read csv file', 'fileName' => $filePath], 'resque');
     $fileInfos = fopen($filePath, "r");
     $newFilePath = ExcelUtil::getDownloadFile($filePath);
     $productNames = $infos = [];
     while (!feof($fileInfos)) {
         $fileInfo = Json::decode(fgets($fileInfos), true);
         if (!empty($fileInfo)) {
             if (in_array($fileInfo['productName'], $productNames) || empty($productNames)) {
                 $infos[] = $fileInfo;
                 $productNames[] = $fileInfo['productName'];
             } else {
                 $args = [$infos, $params];
                 self::writeCsv($classFunction, $args, $header, $newFilePath);
                 unset($infos, $productNames);
                 $productNames[] = $fileInfo['productName'];
                 $infos[] = $fileInfo;
             }
         }
     }
     if (!empty($infos)) {
         $args = [$infos, $params];
         self::writeCsv($classFunction, $args, $header, $newFilePath);
         unset($productNames, $infos);
     }
     fclose($fileInfos);
     LogUtil::info(['message' => 'End to read csv file and end to write file', 'fileName' => $filePath], 'resque');
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:29,代码来源:ExportPromotionCodeAnalysis.php

示例13: createByJson

 /**
  * @param string $json
  * @return static
  */
 public static function createByJson($json)
 {
     $model = new static();
     $attributes = Json::decode($json);
     $model->load($attributes, '');
     return $model;
 }
开发者ID:dw250100785,项目名称:yii2-oauth,代码行数:11,代码来源:BaseModel.php

示例14: _send

 /**
  * @param array $data
  * @param string $method
  *
  * @return ApiResponseOk|ApiResponseError
  */
 private function _send(array $data, $method = 'post')
 {
     $client = new Client(['requestConfig' => ['format' => Client::FORMAT_JSON]]);
     $response = $client->createRequest()->setMethod($method)->setUrl($this->url)->addHeaders(['Content-type' => 'application/json'])->addHeaders(['user-agent' => 'JSON-RPC PHP Client'])->setData($data)->setOptions(['timeout' => $this->timeout])->send();
     //Нам сказали это всегда json. А... нет, все мы люди, бывает и не json )
     try {
         $dataResponse = (array) Json::decode($response->content);
     } catch (\Exception $e) {
         \Yii::error("Json api response error: " . $e->getMessage() . ". Response: \n{$response->content}", self::className());
         //Лайф хак, вдруг разработчики апи оставили var dump
         if ($pos = strpos($response->content, "{")) {
             $content = StringHelper::substr($response->content, $pos, StringHelper::strlen($response->content));
             try {
                 $dataResponse = (array) Json::decode($content);
             } catch (\Exception $e) {
                 \Yii::error("Api response error: " . $response->content, self::className());
             }
         }
     }
     if (!$response->isOk) {
         \Yii::error($response->content, self::className());
         $responseObject = new ApiResponseError($dataResponse);
     } else {
         $responseObject = new ApiResponseOk($dataResponse);
     }
     $responseObject->statusCode = $response->statusCode;
     return $responseObject;
 }
开发者ID:v3toys,项目名称:yii2-api,代码行数:34,代码来源:ApiBase.php

示例15: send

 /**
  * 创建快递跟踪信息
  * @method send
  * @since 0.0.1
  * @param {string} $company 快递公司代码
  * @param {string} $number 快递单号
  * @return {boolean}
  * @example \Yii::$app->express->send($company, $number);
  */
 public function send($company, $number)
 {
     $eid = 0;
     if ($express = Express::findOne(['company' => $company, 'number' => $number])) {
         $eid = $express->id;
     } else {
         $express = new Express();
         $express->company = $company;
         $express->number = $number;
         $express->generateAuthKey();
         if ($express->save()) {
             $result = $this->debug ? ['returnCode' => 200] : Json::decode(Kd100::sdk($this->key)->poll($company, $number, $this->getUrl($express->id), $express->auth_key, $this->resultv2));
             if (isset($result['returnCode'])) {
                 switch ($result['returnCode']) {
                     case 200:
                         $express->status = '提交成功';
                         $eid = $express->id;
                         break;
                     case 501:
                         $express->status = '重复订阅';
                         break;
                 }
                 $express->save();
             }
         }
     }
     return $eid;
 }
开发者ID:xiewulong,项目名称:yii2-express,代码行数:37,代码来源:Manager.php


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