本文整理汇总了PHP中json_decode函数的典型用法代码示例。如果您正苦于以下问题:PHP json_decode函数的具体用法?PHP json_decode怎么用?PHP json_decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_decode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Hywan,项目名称:Amine_and_Hamza,代码行数:7,代码来源:Dates.php
示例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;
}
开发者ID:ttreeagency,项目名称:Embedly,代码行数:11,代码来源:EmbedlyHelper.php
示例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;
}
}
开发者ID:jean-lelarge,项目名称:libZotero,代码行数:32,代码来源:Utils.php
示例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];
}
开发者ID:messyOne,项目名称:Loo-Framework,代码行数:11,代码来源:JsonHandler.php
示例5: xmlToArray
private function xmlToArray($data)
{
$data = simplexml_load_string($data);
$data = json_encode($data);
$data = json_decode($data, true);
return $data;
}
开发者ID:ElvinYusifli,项目名称:PHP-ve-CBAR,代码行数:7,代码来源:CBARCurrencies.php
示例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);
}
开发者ID:lookaflyingdonkey,项目名称:phlow,代码行数:7,代码来源:ActivityTaskScheduled.php
示例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;
}
开发者ID:scaytrase,项目名称:json-rpc-client,代码行数:34,代码来源:JsonRpcResponseCollection.php
示例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;
}
开发者ID:bagi091,项目名称:Selector,代码行数:37,代码来源:selector.class.php
示例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());
}
开发者ID:amdad,项目名称:portfolio,代码行数:27,代码来源:Api.php
示例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;
}
开发者ID:google2013,项目名称:swoole_flash_game,代码行数:37,代码来源:Zpack.php
示例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;
}
}
开发者ID:neworldwebsites,项目名称:noblessecms,代码行数:34,代码来源:pluginstore.php
示例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;
}
}
开发者ID:GabeGibitz,项目名称:DIY,代码行数:26,代码来源:helpers.php
示例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";
}
}
开发者ID:jonboy11171,项目名称:twitter-pos-geotagging,代码行数:30,代码来源:GoogleGeoCodeWebService.php
示例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 . "'");
}
}
开发者ID:howareyoucolin,项目名称:demo,代码行数:7,代码来源:certificates.php
示例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' => '');
}
}
开发者ID:noinlijin,项目名称:tiebaSign,代码行数:29,代码来源:verifyTiezi_cron.php
示例16: put
public function put($url, $body = null)
{
curl_setopt($this->_ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($this->_ch, CURLOPT_URL, $this->_base_uri . $url);
curl_setopt($this->_ch, CURLOPT_POSTFIELDS, json_encode($body));
return json_decode(curl_exec($this->_ch));
}
开发者ID:KopjeKoffie,项目名称:api-examples,代码行数:7,代码来源:liquidplanner.php
示例17: index
public function index()
{
$courses = LearnHub::all();
$res = DB::table('LearnHub')->select('category')->groupBy('category')->get();
$categories = json_decode(json_encode($res), true);
return view('welcome', ['courses' => $courses, 'categories' => $categories]);
}
开发者ID:noddypandey,项目名称:basicangular,代码行数:7,代码来源:LearnhubController.php
示例18: getLiveScore
public static function getLiveScore($requester, $request)
{
$requestParams = explode(",", $request);
$scoreAvailable = false;
$team1 = $requestParams[0];
$team2 = $requestParams[1];
$matchList = file_get_contents(self::$cricInfoURL);
$message = "Sorry, this match information is not available.";
if ($matchList) {
$json = json_decode($matchList, true);
foreach ($json as $value) {
echo $value['t1'] . '/n';
echo $value['t2'] . '/n/n';
if ((stripos($value['t1'], $team1) > -1 || stripos($value['t1'], $team2) > -1) && (stripos($value['t2'], $team1) > -1 || stripos($value['t2'], $team2) > -1)) {
$matchScoreURL = self::$cricInfoURL . '?id=' . $value['id'];
$matchScore = file_get_contents($matchScoreURL);
$matchScore = json_decode($matchScore, true);
$score = $matchScore['0']['de'];
$scoreAvailable = true;
MessaggingController::sendMessage($requester, $score);
}
}
} else {
$message = "Service temporarily not available, please try after some time";
}
if (!$scoreAvailable) {
MessaggingController::sendMessage($requester, $message);
}
PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
}
开发者ID:neerav-mehta,项目名称:yboocs,代码行数:30,代码来源:Cricket.php
示例19: testViewBody
public function testViewBody()
{
// Arrange
$r = $this->socket->get('/public/groups/324e1602-3673-4d52-93ee-eadf94cbea67.json', ["domain" => "netherlands", "limit" => 1]);
// The call should return something
$this->assertNotEquals($r, false);
$r = json_decode($r, true);
$this->checkBasics($r);
// check if the content is ok
$this->assertTrue(isset($r['body']['group']), 'Group should be set in the body');
$g = $r['body']['group'];
$this->assertFalse(empty($g), 'Group should not be empty');
$this->assertTrue(isset($g['uuid']), 'Group uuid should not be empty');
$this->assertTrue(isset($g['serial']), 'Group uuid should not be empty');
$this->assertTrue(isset($g['created']), 'Group creation date should not be empty');
$this->assertTrue(isset($g['modified']), 'Group modification should not be empty');
$this->assertTrue(isset($g['name']), 'Group name should not be empty');
$this->assertTrue(isset($g['mission']), 'Group mission should not be empty');
$this->assertTrue(isset($g['description']), 'Group description should not be empty');
$this->assertTrue(isset($g['picture']), 'Group picture should not be empty');
$this->assertTrue(isset($g['group_type']), 'Group type should not be empty');
$this->assertTrue(isset($g['location']), 'Group location should not be empty');
$this->checkLocation($g['location']);
$this->assertTrue(isset($g['tags']), 'Group tags should not be empty');
// $this->assertTrue(isset($g['url']), 'URL should not be empty'); // GREEN-3436
}
开发者ID:stripthis,项目名称:ggw_api_test,代码行数:26,代码来源:groupTest.php
示例20: testStoreUpdateAndDelete
/**
* Test store, update and delete.
*/
public function testStoreUpdateAndDelete()
{
$requestBody = <<<EOT
{
"data" : {
"type" : "pricelists",
"attributes" : {
"company_id" : "1",
"name": "pricelist_1"
}
}
}
EOT;
// Create
$response = $this->callPost(self::API_URL, $requestBody);
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
$this->assertNotNull($obj = json_decode($response->getContent())->data);
$this->assertNotEmpty($obj->id);
//$this->assertNotEmpty($obj->headers->get('Location'));
// re-read and check
$this->assertNotNull($obj = json_decode($this->callGet(self::API_URL . $obj->id)->getContent())->data);
$this->assertEquals('pricelist_1', $obj->attributes->name);
// Update
$requestBody = "{\n \"data\" : {\n \"type\" : \"pricelists\",\n \"id\" : \"{$obj->id}\",\n \"attributes\" : {\n \"company_id\" : \"1\",\n \"name\" : \"pricelist_2\"\n }\n }\n }";
Log::info($requestBody);
$response = $this->callPatch(self::API_URL . $obj->id, $requestBody);
Log::info($response);
$this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());
// re-read and check
$this->assertNotNull($obj = json_decode($this->callGet(self::API_URL . $obj->id)->getContent())->data);
$this->assertEquals('pricelist_2', $obj->attributes->name);
// Delete
$response = $this->callDelete(self::API_URL . $obj->id);
$this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());
}
开发者ID:guduchango,项目名称:limoncello,代码行数:38,代码来源:PricelistTest.php
注:本文中的json_decode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论