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


PHP json::decode方法代码示例

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


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

示例1: unwrap

 static function unwrap($token, $domains, $address = null)
 {
     if ($package = base64_decode($token, true)) {
         if ($package = json::decode($package)) {
             if (isset($package->value) and isset($package->domain) and isset($package->expire_at) and isset($package->digest)) {
                 $digest = $package->digest;
                 unset($package->digest);
                 if ($digest === self::digest($package)) {
                     if (isset($package->address)) {
                         if (is_null($address) or $package->address !== $address) {
                             return null;
                         }
                     }
                     if ($package->expire_at === 0 or $package->expire_at > @time()) {
                         foreach ($domains as $domain) {
                             if (ends_with('.' . $package->domain, '.' . $domain)) {
                                 return $package->value;
                             }
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:26,代码来源:security.php

示例2: make_call

 public function make_call($path, $data = array(), $method = "GET")
 {
     $fields = $this->getFields($data);
     $field_string = implode('&', $fields);
     //open connection
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //what type of request?
     if ($method == "GET") {
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path . '?' . $field_string);
     } elseif ($method == "POST" || $method == "PATCH" || $method == "DELETE") {
         if ($method == "PATCH") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
         }
         if ($method == "DELETE") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
         }
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path);
         curl_setopt($ch, CURLOPT_POST, count($fields));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
     }
     //execute post
     $result = curl_exec($ch);
     //close connection
     curl_close($ch);
     //send our data back
     return json::decode($result);
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:28,代码来源:thingiverseapi.php

示例3: request

 function request($type, $url, $get = [], $post = [])
 {
     $developer = cookie::developer();
     if ($developer) {
         $get['_mode'] = 'developer';
     }
     $request = ['method' => $type, 'protocol_version' => '1.1', 'header' => 'Connection: Close'];
     foreach ($post as $name => &$param) {
         if (is_array($param) and empty($param)) {
             $param = '_empty_array';
         }
     }
     if (!empty($post)) {
         $request['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
         $request['content'] = http_build_query($post);
     }
     $ctx = stream_context_create(['http' => $request]);
     $response = file_get_contents($this->endpoint . (empty($get) ? $url : $url . '?' . http_build_query($get)), false, $ctx);
     $object = json::decode($response, true);
     if (is_null($object)) {
         if ($developer) {
             var_dump($response);
             die;
         } else {
             throw new Exception("Error Processing Request", 1);
         }
     }
     $content = $object['content'];
     return (is_object($content) or is_array($content) and array_values($content) !== $content) ? (object) $content : $content;
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:30,代码来源:api.php

示例4: query_direct

 function query_direct($args)
 {
     switch ($this->method) {
         case 'photos':
             isset($args['_venue_id']) or backend_error('bad_query', 'Foursquare _venue_id argument missing');
             $photos = [];
             if ($result = json::decode(file_get_contents('https://api.foursquare.com/v2/venues/' . $args['venue_id'] . '/photos?' . $this->foursquare->get()))) {
                 foreach ($result->response->photos->groups as $group) {
                     if ($group->type == 'venue') {
                         foreach ($group->items as $item) {
                             $photo = ['url' => $item->url, 'created' => $item->createdAt, 'user' => ['id' => $item->user->id, 'firstName' => $item->user->firstName, 'lastName' => @$item->user->lastName, 'gender' => $item->user->gender, 'photo' => $item->user->photo]];
                             $resampled = [];
                             foreach ($item->sizes->items as $size) {
                                 $resampled[] = ['url' => $size->url, 'width' => $size->width, 'height' => $size->height];
                             }
                             $photo['resampled'] = $resampled;
                             $photos[] = $photo;
                         }
                     }
                 }
             }
             !(empty($photos) and $this->required) or backend_error('bad_input', 'Empty response from Froursquare procedure');
             return (object) $photos;
         case 'venues':
             isset($args['_latitude']) or backend_error('bad_query', 'Foursquare _latitude argument missing');
             isset($args['_longitude']) or backend_error('bad_query', 'Foursquare _longitude argument missing');
             $venues = [];
             if ($result = json::decode(file_get_contents('https://api.foursquare.com/v2/venues/search?ll=' . $args['_latitude'] . ',' . $args['_longitude'] . '&' . $this->foursquare->get()))) {
                 foreach ($result->response->groups as $group) {
                     if ($group->type == 'nearby') {
                         foreach ($group->items as $item) {
                             $venue[] = ['id' => $item->id, 'name' => $item->name, 'url' => $item->canonicalUrl];
                             $categories = [];
                             foreach ($item->categories as $category) {
                                 $categories[] = ['id' => $category->id, 'name' => $category->name, 'pluralName' => $category->pluralName, 'shortName' => $category->shortName, 'icon' => $category->icon];
                             }
                             $venue['categories'] = $categories;
                             $venues[] = $venue;
                         }
                     }
                 }
             }
             !(empty($venues) and $this->required) or backend_error('bad_input', 'Empty response from Froursquare procedure');
             return (object) $venues;
     }
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:46,代码来源:foursquare_procedure.php

示例5: make_call

 public function make_call($path, $data = array(), $method = "GET")
 {
     //our parameters for the call
     $data['client_id'] = $this->client_id;
     $data['client_secret'] = $this->client_secret;
     $data['access_token'] = $this->user_token;
     //url-ify the data for the call
     $fields_string = "";
     $fieldsCount = 0;
     foreach ($data as $key => $value) {
         $fields_string .= $key . '=' . $value . '&';
         $fieldsCount++;
     }
     rtrim($fields_string, '&');
     //open connection
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //what type of request?
     if ($method == "GET") {
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path . '?' . $fields_string);
     } elseif ($method == "POST" || $method == "PATCH" || $method == "DELETE") {
         if ($method == "PATCH") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
         }
         if ($method == "DELETE") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
         }
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path);
         curl_setopt($ch, CURLOPT_POST, $fieldsCount);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     }
     //execute post
     $result = curl_exec($ch);
     //$info = curl_getinfo($ch);
     //close connection
     curl_close($ch);
     //send our data back
     return json::decode($result);
 }
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:39,代码来源:thingiverseapi.php

示例6: getDriverConfig

 public function getDriverConfig()
 {
     //load up our config
     $config = json::decode($this->get('driver_config'));
     if (!is_object($config)) {
         $config = new stdClass();
     }
     $config->name = $this->getName();
     //default our slicing value
     if (!isset($config->can_slice)) {
         $config->can_slice = True;
     }
     return $config;
 }
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:14,代码来源:bot.php

示例7: json

 function json_decode($string, $type = 1)
 {
     require_once 'json.class.php';
     $json = new json();
     return $json->decode($string, $type);
 }
开发者ID:hardy419,项目名称:2015-7-27,代码行数:6,代码来源:global.func.php

示例8: request

 function request($params, $global, $get, $post, $cookies, $files, $extensions)
 {
     $values = [];
     $batch = [];
     foreach (array_merge($global, $this->params) as $name => $param) {
         $value = self::substitute($param->value, $params);
         switch ($param->type) {
             case 'value':
                 $values[$name] = $value;
                 break;
             case 'json':
                 $values[$name] = json::decode(fs::checked_read($value));
                 break;
             case 'xml':
                 $values[$name] = 'TODO: Add XML support here';
                 break;
             case 'query':
                 $batch[$name] = $value;
                 break;
             case 'get':
                 isset($get[$value]) or isset($param->default) or runtime_error('GET parameter not found: ' . $name);
                 $values[$name] = isset($get[$value]) ? $get[$value] : $param->default;
                 break;
             case 'post':
                 isset($post[$value]) or isset($param->default) or runtime_error('POST parameter not found: ' . $name);
                 $values[$name] = isset($post[$value]) ? $post[$value] : $param->default;
                 break;
             case 'cookie':
                 isset($cookies[$value]) or isset($param->default) or runtime_error('Cookie parameter not found: ' . $name);
                 $values[$name] = isset($cookies[$value]) ? $cookies[$value] : $param->default;
                 break;
         }
     }
     foreach ($batch as $name => &$value) {
         $value = preg_replace_callback('/\\{@(\\w+)\\}/', function ($matches) use($values) {
             return isset($values[$matches[1]]) ? $values[$matches[1]] : $matches[0];
         }, $value);
     }
     $response = [];
     $params = array_merge($values, empty($batch) ? [] : $this->api->batch($batch));
     if ($this->script) {
         $script_args = $params;
         if ($this->files) {
             $script_args = array_merge($script_args, [$this->files => $files]);
         }
         $prototype = '$' . implode(',$', array_keys($script_args));
         $script = '';
         foreach ($this->require as $require) {
             $script .= 'require_once(\'' . $this->scripts . $require . '\');';
         }
         $script .= 'return function(' . (empty($script_args) ? '' : $prototype) . ") { {$this->script} };";
         $closure = eval($script);
         if ($result = call_user_func_array($closure->bindTo($this->api), array_values($script_args))) {
             $params = array_replace($params, $result);
         }
         foreach (['cookies', 'redirect', 'headers'] as $builtin) {
             $mangled = '_' . $builtin;
             if (isset($params[$mangled])) {
                 $response[$builtin] = $params[$mangled];
                 unset($params[$mangled]);
             }
         }
     }
     if ($this->template) {
         switch ($this->engine) {
             case 'twig':
                 $loader = new Twig_Loader_Filesystem($this->templates);
                 $options = [];
                 if ($this->cache) {
                     $options['cache'] = $this->cache;
                 }
                 $twig = new Twig_Environment($loader, $options);
                 //$twig->addExtension(new Twig_Extension_Debug());
                 $twig->getExtension('core')->setNumberFormat(0, '.', ' ');
                 $closure = function ($haystack, $needle) {
                     return $needle === "" or strpos($haystack, $needle) === 0;
                 };
                 $function = new Twig_SimpleFunction('starts_with', $closure);
                 $twig->addFunction($function);
                 $closure = function ($filename) {
                     return json_decode(file_get_contents($this->data . $filename));
                 };
                 $function = new Twig_SimpleFunction('json', $closure->bindTo($this, $this));
                 $twig->addFunction($function);
                 $closure = function ($object) {
                     $array = [];
                     foreach ($object as $key => $value) {
                         $array[$key] = $value;
                     }
                     return $array;
                 };
                 $filter = new Twig_SimpleFilter('array', $closure);
                 $twig->addFilter($filter);
                 $closure = function ($number) {
                     return ceil($number);
                 };
                 $filter = new Twig_SimpleFilter('ceil', $closure);
                 $twig->addFilter($filter);
                 $closure = function ($string) {
                     return md5($string);
//.........这里部分代码省略.........
开发者ID:nyan-cat,项目名称:easyweb,代码行数:101,代码来源:page.php

示例9: driver_form

 public function driver_form()
 {
     try {
         //load our bot
         $bot = new Bot($this->args('id'));
         if (!$bot->isHydrated()) {
             throw new Exception("Could not find that bot.");
         }
         if (!$bot->isMine()) {
             throw new Exception("You cannot view that bot.");
         }
         if ($this->args('token_id') == 0) {
             $this->set('nodriver', "No driver was selected");
         } else {
             //load our token
             $token = new OAuthToken($this->args('token_id'));
             if (!$token->isHydrated()) {
                 throw new Exception("Could not find that computer.");
             }
             if (!$token->isMine()) {
                 throw new Exception("This is not your computer.");
             }
             //what driver form to create?
             $driver = $this->args('driver');
             //pass on our info.
             $this->set('bot', $bot);
             $this->set('driver', $driver);
             $this->set('token', $token);
             $devices = json::decode($token->get('device_data'));
             $this->set('devices', $devices);
             //pull in our driver config
             $driver_config = $bot->getDriverConfig();
             //if we're using the same driver, pull in old values...
             if ($driver == $bot->get('driver_name')) {
                 $this->set('driver_config', $driver_config);
                 if (is_object($driver_config)) {
                     $this->set('delay', $driver_config->delay);
                     $this->set('serial_port', $driver_config->port);
                     $this->set('baudrate', $driver_config->baud);
                 }
             } else {
                 if ($driver == "dummy") {
                     $this->set('delay', '0.001');
                 }
             }
             //pull in our old webcam values too.
             if (is_object($driver_config) && !empty($driver_config->webcam)) {
                 $this->set('webcam_id', $driver_config->webcam->id);
                 $this->set('webcam_name', $driver_config->webcam->name);
                 $this->set('webcam_device', $driver_config->webcam->device);
                 $this->set('webcam_brightness', $driver_config->webcam->brightness);
                 $this->set('webcam_contrast', $driver_config->webcam->contrast);
             } else {
                 //some default webcam settings.
                 $this->set('webcam_id', '');
                 $this->set('webcam_name', '');
                 $this->set('webcam_device', '');
                 $this->set('webcam_brightness', 50);
                 $this->set('webcam_contrast', 50);
             }
             $this->set('driver_config', $driver_config);
             $this->set('baudrates', array(250000, 115200, 57600, 38400, 28880, 19200, 14400, 9600));
         }
     } catch (Exception $e) {
         $this->set('megaerror', $e->getMessage());
     }
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:67,代码来源:bot_edit.php

示例10: jsonDecode

function jsonDecode($str)
{
    $json = new json();
    return $json->decode($str);
}
开发者ID:austinliniware,项目名称:tsci-rota,代码行数:5,代码来源:json.fun.php

示例11: canonizeEvent

 public function canonizeEvent($extra, $event = array())
 {
     // Check
     if (empty($extra)) {
         return '';
     }
     // object to array
     if (is_object($extra)) {
         $extra = $extra->toArray();
     }
     // Make register_discount
     $extra['register_discount'] = json::decode($extra['register_discount'], true);
     // Set register_details
     $extra['register_details'] = Pi::service('markup')->render($extra['register_details'], 'html', 'html');
     // Set time
     $extra['time_start_view'] = empty($extra['time_start']) ? '' : _date($extra['time_start'], array('pattern' => 'yyyy-MM-dd'));
     $extra['time_end_view'] = empty($extra['time_end']) ? '' : _date($extra['time_end'], array('pattern' => 'yyyy-MM-dd'));
     // Set register_price
     if (is_numeric($extra['register_price']) && $extra['register_price'] > 0) {
         $uid = Pi::user()->getId();
         $roles = Pi::user()->getRole($uid);
         if (!empty($extra['register_discount'])) {
             $price = $extra['register_price'];
             foreach ($extra['register_discount'] as $role => $percent) {
                 if (isset($percent) && $percent > 0 && in_array($role, $roles)) {
                     $price = $extra['register_price'] - $extra['register_price'] * ($percent / 100);
                 }
             }
             $extra['register_price'] = $price;
         }
         if (Pi::service('module')->isActive('order')) {
             $priceView = Pi::api('api', 'order')->viewPrice($extra['register_price']);
         } else {
             $priceView = _currency($extra['register_price']);
         }
     } else {
         $priceView = _currency($extra['register_price']);
     }
     // Set order
     $config = Pi::service('registry')->config->read($this->getModule());
     if ($config['order_active']) {
         if ($extra['register_price'] > 0 && $extra['register_stock'] > 0) {
             $extra['register_price_view'] = $priceView;
         } elseif ($extra['register_price'] > 0 && $extra['register_stock'] == 0) {
             $extra['register_price_view'] = sprintf(__('Out of stock ( %s )'), $priceView);
         } else {
             $extra['register_price_view'] = __('free!');
         }
     } else {
         if (is_numeric($extra['register_price']) && $extra['register_price'] > 0) {
             $extra['register_price_view'] = _currency($extra['register_price']);
         } else {
             $extra['register_price_view'] = __('free!');
         }
     }
     // Set currency
     $configSystem = Pi::service('registry')->config->read('system');
     $extra['price_currency'] = empty($configSystem['number_currency']) ? 'USD' : $configSystem['number_currency'];
     // canonize guide module details
     $extra['guide_category'] = Json::decode($extra['guide_category'], true);
     $extra['guide_location'] = Json::decode($extra['guide_location'], true);
     $extra['guide_item'] = Json::decode($extra['guide_item'], true);
     // Set event url
     $extra['eventUrl'] = Pi::url(Pi::service('url')->assemble('event', array('module' => $this->getModule(), 'controller' => 'index', 'slug' => $extra['slug'])));
     // Set register url
     $extra['eventOrder'] = Pi::url(Pi::service('url')->assemble('event', array('module' => $this->getModule(), 'controller' => 'register', 'action' => 'add')));
     // Set category
     if (isset($event['topics']) && !empty($event['topics'])) {
         $topicList = array();
         foreach ($event['topics'] as $topic) {
             $topicList[] = array('title' => $topic['title'], 'url' => Pi::url(Pi::service('url')->assemble('event', array('module' => $this->getModule(), 'controller' => 'category', 'slug' => $topic['slug']))));
         }
         $extra['topics'] = $topicList;
     }
     // Check guide module
     if (Pi::service('module')->isActive('guide') && !empty($extra['guide_location'])) {
         $locationList = Pi::registry('locationList', 'guide')->read();
         $extra['locationInfo'] = $locationList[$extra['guide_location'][0]];
     }
     return $extra;
 }
开发者ID:pi-module,项目名称:event,代码行数:81,代码来源:Event.php

示例12: json

 static function json($root, $json)
 {
     $xml = new xml();
     $xml->append(self::assoc_node($xml, $root, json::decode($json, true)));
     return $xml;
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:6,代码来源:xml.php

示例13: json_decode

 function json_decode($string) {
     return json::decode($string);
 }
开发者ID:jiangsuei8,项目名称:public_php_shl,代码行数:3,代码来源:front_class.php

示例14: json

 function json($url)
 {
     $json = self::get($url);
     return json::decode($json);
 }
开发者ID:rev087,项目名称:kennel,代码行数:5,代码来源:rest.php

示例15: getArenaTeam

 public function getArenaTeam($realm, $teamname, $size, $fields = null)
 {
     // URL: /api/wow/arena/{realm}/{size}/{name} (size being 2v2, 3v3 or 5v5)
     // Basic information: name, ranking, rating, weekly/season statistics
     // Optional fields: members (roster)
     $url = sprintf('http://%s.battle.net/api/wow/arena/%s/%s/%s', $this->region, $realm, $size, $teamname);
     $request = new HttpRequest($url);
     $ret = json::decode((string) $request);
     return $ret;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:10,代码来源:wow.php


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