本文整理汇总了PHP中json_decode函数的典型用法代码示例。如果您正苦于以下问题:PHP json_decode函数的具体用法?PHP json_decode怎么用?PHP json_decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($limit = 1024)
{
header('Content-Type: application/json');
$dates = json_decode(file_get_contents('hoa://Application/Database/Dates.json'), true);
echo json_encode(array_slice($dates, 0, $limit));
return;
}
示例2: oembed
/**
* @param string $url
* @return array
*/
public function oembed($url)
{
$embedly = new Embedly();
$response = $embedly->oembed(['url' => $url]);
$data = json_decode(json_encode(reset($response)), true);
return $data;
}
示例3: updateObjectsFromWriteResponse
public static function updateObjectsFromWriteResponse($objectsArray, $response)
{
$data = json_decode($response->getRawBody(), true);
if ($response->getStatus() == 200) {
$newLastModifiedVersion = $response->getHeader("Last-Modified-Version");
if (isset($data['success'])) {
foreach ($data['success'] as $ind => $key) {
$i = intval($ind);
$object = $objectsArray[$i];
$objectKey = $object->get('key');
if ($objectKey != '' && $objectKey != $key) {
throw new Exception("Item key mismatch in multi-write request");
}
if ($objectKey == '') {
$object->set('key', $key);
}
$object->set('version', $newLastModifiedVersion);
$object->synced = true;
$object->writeFailure = false;
}
}
if (isset($data['failed'])) {
foreach ($data['failed'] as $ind => $val) {
$i = intval($ind);
$object = $objectsArray[$i];
$object->writeFailure = $val;
}
}
} elseif ($response->getStatus() == 204) {
$objectsArray[0]->synced = true;
}
}
示例4: load
/**
* @param bool|true $assoc
* @return array
*/
public function load($assoc = true)
{
if (!isset(static::$cache[$this->file])) {
static::$cache[$this->file] = json_decode($this->loadFile(), $assoc);
}
return static::$cache[$this->file];
}
示例5: xmlToArray
private function xmlToArray($data)
{
$data = simplexml_load_string($data);
$data = json_encode($data);
$data = json_decode($data, true);
return $data;
}
示例6: inflate
private function inflate()
{
$this->name = $this->raw['activityTaskScheduledEventAttributes']['activityType']['name'];
$this->version = $this->raw['activityTaskScheduledEventAttributes']['activityType']['version'];
$this->control = $this->raw['activityTaskScheduledEventAttributes']['control'];
$this->inputs = json_decode(base64_decode($this->raw['activityTaskScheduledEventAttributes']['input']), true);
}
示例7: sync
private function sync()
{
if ($this->synchronized) {
return;
}
/** @var ResponseInterface $clientResponse */
$clientResponse = $this->promise->wait();
if (200 !== $clientResponse->getStatusCode()) {
throw new RemoteCallFailedException();
}
$data = (string) $clientResponse->getBody();
// Null (empty response) is expected if only notifications were sent
$rawResponses = [];
if ('' !== $data) {
$rawResponses = json_decode($data, false);
if (json_last_error() !== JSON_ERROR_NONE) {
throw ResponseParseException::notAJsonResponse();
}
}
if (!is_array($rawResponses) && $rawResponses instanceof \stdClass) {
$rawResponses = [$rawResponses];
}
$this->responses = [];
foreach ($rawResponses as $rawResponse) {
try {
$response = new SyncResponse($rawResponse);
} catch (ResponseParseException $exception) {
//todo: logging??? (@scaytrase)
continue;
}
$this->responses[$response->getId()] = $response;
}
$this->synchronized = true;
}
示例8: renderJS
/**
* @param $list
* @param array $ph
* @return string
*/
public function renderJS($list, $ph = array())
{
$js = '';
$scripts = MODX_BASE_PATH . $list;
if ($this->fs->checkFile($scripts)) {
$scripts = @file_get_contents($scripts);
$scripts = $this->DLTemplate->parseChunk('@CODE:' . $scripts, $ph);
$scripts = json_decode($scripts, true);
$scripts = isset($scripts['scripts']) ? $scripts['scripts'] : $scripts['styles'];
foreach ($scripts as $name => $params) {
if (!isset($this->modx->loadedjscripts[$name])) {
if ($this->fs->checkFile($params['src'])) {
$this->modx->loadedjscripts[$name] = array('version' => $params['version']);
if (end(explode('.', $params['src'])) == 'js') {
$js .= '<script type="text/javascript" src="' . $this->modx->config['site_url'] . $params['src'] . '"></script>';
} else {
$js .= '<link rel="stylesheet" type="text/css" href="' . $this->modx->config['site_url'] . $params['src'] . '">';
}
} else {
$this->modx->logEvent(0, 3, 'Cannot load ' . $params['src'], $this->customTvName);
}
}
}
} else {
if ($list == $this->jsListDefault) {
$this->modx->logEvent(0, 3, "Cannot load {$this->jsListDefault} .", $this->customTvName);
} elseif ($list == $this->cssListDefault) {
$this->modx->logEvent(0, 3, "Cannot load {$this->cssListDefault} .", $this->customTvName);
}
}
return $js;
}
示例9: entries
public function entries()
{
$collection = $this->param("collection", null);
$entries = [];
if ($collection) {
$col = "collection" . $collection["_id"];
$options = [];
if ($collection["sortfield"] && $collection["sortorder"]) {
$options["sort"] = [];
$options["sort"][$collection["sortfield"]] = $collection["sortorder"];
}
if ($filter = $this->param("filter", null)) {
$options["filter"] = is_string($filter) ? json_decode($filter, true) : $filter;
}
if ($limit = $this->param("limit", null)) {
$options["limit"] = $limit;
}
if ($sort = $this->param("sort", null)) {
$options["sort"] = $sort;
}
if ($skip = $this->param("skip", null)) {
$options["skip"] = $skip;
}
$entries = $this->app->db->find("collections/{$col}", $options);
}
return json_encode($entries->toArray());
}
示例10: parse
/**
* client包格式: writeString(json_encode(array("a"='main/main',"m"=>'main', 'k1'=>'v1')));
* server包格式:包总长+数据(json_encode)
* @param $_data
* @return bool
*/
public function parse($_data)
{
if (!empty($this->_buffer[$this->fd])) {
$_data = $this->_buffer . $_data;
}
$packData = new MessagePacker($_data);
$packLen = $packData->readInt();
$dataLen = \strlen($_data);
if ($packLen > $dataLen) {
$this->_buffer[$this->fd] = $_data;
return false;
} elseif ($packLen < $dataLen) {
$this->_buffer[$this->fd] = \substr($_data, $packLen, $dataLen - $packLen);
} else {
if (!empty($this->_buffer[$this->fd])) {
unset($this->_buffer[$this->fd]);
}
}
$packData->resetOffset();
$params = $packData->readString();
$this->_params = \json_decode($params, true);
$apn = Config::getField('project', 'ctrl_name', 'a');
$mpn = Config::getField('project', 'method_name', 'm');
if (isset($params[$apn])) {
$this->_ctrl = \str_replace('/', '\\', $params[$apn]);
}
if (isset($params[$mpn])) {
$this->_method = $params[$mpn];
}
return $this->_params;
}
示例11: loadApi
function loadApi($action)
{
switch ($action) {
case 'install':
if (!isset($_COOKIE['groupid'])) {
throw new Exception("Error Processing Request");
}
$url = Request::get('send_url', '');
$send_method = Request::get('send_method', 'plugin');
if (!isset($url[4])) {
throw new Exception("Error Processing Request");
}
$path = 'contents/plugins/';
if ($send_method == 'template') {
$path = 'contents/themes/';
}
File::downloadModule($url, $path, 'yes');
break;
case 'load':
$queryData = array('send_catid' => Request::get('send_catid', 0), 'is_filter' => Request::get('is_filter', 'no'), 'send_keyword' => Request::get('send_keyword', ''), 'send_page' => Request::get('send_page', 0), 'send_limitshow' => Request::get('send_limitshow', 20), 'send_method' => Request::get('send_method', 'plugin'), 'send_showtype' => Request::get('send_showtype', 'lastest'));
$loadData = PluginStoreApi::get($queryData);
$loadData = json_decode($loadData, true);
if ($loadData['error'] == 'yes') {
throw new Exception($loadData['message']);
}
return $loadData['data'];
break;
case 'loadhtml':
$queryData = array('send_catid' => Request::get('send_catid', 0), 'is_filter' => Request::get('is_filter', 'no'), 'send_keyword' => Request::get('send_keyword', ''), 'send_page' => Request::get('send_page', 0), 'send_limitshow' => Request::get('send_limitshow', 20), 'send_method' => Request::get('send_method', 'plugin'), 'send_showtype' => Request::get('send_showtype', 'lastest'));
$loadData = PluginStoreApi::getHTML($queryData);
return $loadData;
break;
}
}
示例12: getElementsData
function getElementsData() {
$elements_dirname = ADMIN_BASE_PATH.'/components/elements';
if ($elements_dir = opendir($elements_dirname)) {
$tmpArray = array();
while (false !== ($dir = readdir($elements_dir))) {
if (substr($dir,0,1) != "." && is_dir($elements_dirname . '/' . $dir)) {
$tmpKey = strtolower($dir);
if (@file_exists($elements_dirname . '/' . $dir . '/metadata.json')) {
$tmpValue = json_decode(@file_get_contents($elements_dirname . '/' . $dir . '/metadata.json'));
if ($tmpValue) {
$tmpArray["$tmpKey"] = $tmpValue;
}
}
}
}
closedir($elements_dir);
if (count($tmpArray)) {
return $tmpArray;
} else {
return false;
}
} else {
echo 'not dir';
return false;
}
}
示例13: getLatandLong
function getLatandLong($addr, $region)
{
$url = "http://maps.google.com/maps/api/geocode/json?address=" . $addr . "®ion=" . $region . "&sensor=false";
$response = file_get_contents($url);
if ($response == false) {
throw new Exception("Failure to obtain data");
}
$places = json_decode($response);
if (!$places) {
throw new Exception("Invalid JSON response");
}
if (is_array($places->results) && count($places->results)) {
$result = $places->results[0];
$geometry = $result->{'geometry'};
$location = $geometry->{'location'};
$lat = $location->{'lat'};
$long = $location->{'lng'};
ob_start();
// ensures anything dumped out will be caught
// do stuff here
//header( "Location: $url" );
//return $lat.",".$long;
// clear out the output buffer
while (ob_get_status()) {
ob_end_clean();
}
} else {
return "Unknown";
}
}
示例14: saveSort
public function saveSort($data = array())
{
$sort_arr = json_decode(htmlspecialchars_decode($data['sort_string']));
foreach ($sort_arr as $key => $id) {
$query = $this->db->query("update aa_certificates set sort='" . $key . "' where id='" . $id . "'");
}
}
示例15: verifyTiezi_send
function verifyTiezi_send($uid, $tid, $pid, $water = 'StusGame Tieba Cloud Sign Plugin "verifyTiezi"', $device = 4)
{
if (empty($uid) || empty($tid) || empty($pid)) {
return array('status' => '1', 'msg' => '');
}
$ck = misc::GetCookie($pid);
$xs = verifyTiezi_gettie($tid, $ck);
$x = array('BDUSS' => $ck, '_client_id' => 'wappc_136' . rand_int(10) . '_' . rand_int(3), '_client_type' => $device, '_client_version' => '5.0.0', '_phone_imei' => md5(rand_int(16)), 'anonymous' => '0', 'content' => $water, 'fid' => $xs['fid'], 'kw' => $xs['word'], 'net_type' => '3', 'tbs' => $xs['tbs'], 'tid' => $tid, 'title' => '');
$y = '';
foreach ($x as $key => $value) {
$y .= $key . '=' . $value;
}
$x['sign'] = strtoupper(md5($y . 'tiebaclient!!!'));
$c = new wcurl('http://c.tieba.baidu.com/c/c/post/add', array('Content-Type: application/x-www-form-urlencoded'));
/* //Note:普通的
$x = verifyTiezi_gettie($tid,$ck);
$c = new wcurl('http://tieba.baidu.com'.$x['__formurl']);
unset($x['__formurl']);
$x['co'] = $water;
*/
$c->addcookie('BDUSS=' . $ck);
$return = json_decode($c->post($x), true);
$c->close();
if (!empty($return['error_code']) && $return['error_code'] != '1') {
return array('status' => $return['error_code'], 'msg' => $return['error_msg']);
} else {
return array('status' => '1', 'msg' => '');
}
}