本文整理汇总了PHP中JSON::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::decode方法的具体用法?PHP JSON::decode怎么用?PHP JSON::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSON
的用法示例。
在下文中一共展示了JSON::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function test_table()
{
$input = <<<EOF
^ H 1 ^ H 2 ^ H 3 ^ ** H 4 ** ^
| R 1 C 1 | R 1 C 2 || R 1 Col 4 |
| R 2 C 1 | ::: || R 2 Col 4 |
| R 3 C 1 | R 3 C 2 | R 3 C 3 | R 3 Col 4 |
EOF;
$data = array(array('H 1', 'H 2', 'H 3', '** H 4 **'), array('R 1 C 1', 'R 1 C 2', '', 'R 1 Col 4'), array('R 2 C 1', ':::', '', 'R 2 Col 4'), array('R 3 C 1', 'R 3 C 2', 'R 3 C 3', 'R 3 Col 4'));
$meta = array(array(array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'th'), array('align' => 'center', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'th'), array('align' => 'right', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'th'), array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'th')), array(array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td'), array('align' => 'left', 'colspan' => 2, 'rowspan' => 2, 'tag' => 'td'), array('hide' => true, 'rowspan' => 1, 'colspan' => 1), array('align' => null, 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td')), array(array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td'), array('hide' => true, 'rowspan' => 1, 'colspan' => 1), array('hide' => true, 'rowspan' => 1, 'colspan' => 1), array('align' => null, 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td')), array(array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td'), array('align' => 'left', 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td'), array('align' => null, 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td'), array('align' => null, 'colspan' => 1, 'rowspan' => 1, 'tag' => 'td')));
$renderer = $this->render($input);
$json = new JSON(JSON_LOOSE_TYPE);
$this->assertEquals($data, $json->decode($renderer->getDataJSON()));
$this->assertEquals($meta, $json->decode($renderer->getMetaJSON()));
}
示例2: processTen
private function processTen()
{
$prepared = $this->db->prepare('
SELECT *
FROM `jobs`
WHERE `status` = :status
ORDER BY `created_at`
LIMIT 10
');
$prepared->execute([':status' => self::QUEUED]);
foreach ($prepared->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (isset(self::$handlers[$row['handler']])) {
$class = self::$handlers[$row['handler']];
$worker = new $class();
$this->db->beginTransaction();
try {
$this->setStatus($row['id'], self::PROCESSING);
$worker->work(JSON::decode($row['message']));
$this->setStatus($row['id'], self::FINISHED);
$this->db->commit();
} catch (Exception $e) {
echo $e;
$this->db->rollBack();
error_log('job_log: ' . $e);
}
}
}
}
示例3: get
public static function get()
{
$rmFile = preg_replace("/\\/\\*([^x00]*)\\*?\\/?\\*\\//U", "", Filesystem::getFileContent(Config::ROADMAP));
$roadMap = JSON::decode($rmFile, true);
$tmpl = self::$_attr;
$cnt = 0;
$good = is_array($roadMap);
//print_r( $roadMap ); die;
for ($i = 0; $good && is_array($roadMap) && $i < count($roadMap); $i++) {
$el = $roadMap[$i];
foreach ($el as $k => $v) {
if (($pos = array_search($k, $tmpl)) !== FALSE) {
$tmpl[$pos] = "asnfcjrwpht984fh9prewgf84fds";
$cnt++;
}
}
$good = $cnt == count(self::$_attr);
}
if ($good) {
return $roadMap;
} else {
self::raiseException(ERR_ROADMAP);
return NULL;
}
}
示例4: testDecoding
public function testDecoding()
{
$formatter = new JSON();
$data = (object) array('name' => 'Joe', 'age' => 21, 'employed' => true);
$raw = '{"name":"Joe","age":21,"employed":true}';
$this->assertEquals($data, $formatter->decode($raw));
}
示例5: download
/**
* 下载文件
* @param string|array $file_name 文件名,可以为数组
*/
public function download($from_version, $to_version = null)
{
if ($to_version == null) {
$to_version = $this->version;
}
$url = self::URL . "file.php?name={$this->name}&from={$from_version}&to={$to_version}";
$fileinfo = self::get($url);
if (trim($fileinfo) == "") {
return false;
}
$fileinfo = JSON::decode($fileinfo);
$bak_path = $this->init_bak_path();
$bak_zip = new ZipArchive();
$bak_zip->open($bak_path, ZIPARCHIVE::CREATE);
foreach ($fileinfo as $key => $value) {
$tmp_path = ltrim($value['path'], "./\\");
if (file_exists($tmp_path)) {
$bak_zip->addFile($tmp_path);
}
}
$bak_zip->close();
$url = self::URL . "download.php?name={$this->name}&from={$from_version}&to={$to_version}";
$content = self::get($url);
$tmp_path = microtime(true) . mt_rand(1, 10000) . ".zip";
file_put_contents($tmp_path, $content);
/*
$bak_zip->open($tmp_path,ZIPARCHIVE::CREATE);
$bak_zip->extractTo("./");
$bak_zip->close();
unlink($tmp_path);
return true;
*/
return $tmp_path;
}
示例6: verifyNotify
/**
* 针对notify_url验证消息是否是连连支付发出的合法消息
* @return 验证结果
*/
function verifyNotify()
{
//生成签名结果
$is_notify = true;
include_once 'llpay_cls_json.php';
$json = new JSON();
$str = file_get_contents("php://input");
$val = $json->decode($str);
$oid_partner = trim($val->{'oid_partner'});
$sign_type = trim($val->{'sign_type'});
$sign = trim($val->{'sign'});
$dt_order = trim($val->{'dt_order'});
$no_order = trim($val->{'no_order'});
$oid_paybill = trim($val->{'oid_paybill'});
$money_order = trim($val->{'money_order'});
$result_pay = trim($val->{'result_pay'});
$settle_date = trim($val->{'settle_date'});
$info_order = trim($val->{'info_order'});
$pay_type = trim($val->{'pay_type'});
$bank_code = trim($val->{'bank_code'});
$no_agree = trim($val->{'no_agree'});
$id_type = trim($val->{'id_type'});
$id_no = trim($val->{'id_no'});
$acct_name = trim($val->{'acct_name'});
//首先对获得的商户号进行比对
if ($oid_partner != $this->llpay_config['oid_partner']) {
//商户号错误
return false;
}
$parameter = array('oid_partner' => $oid_partner, 'sign_type' => $sign_type, 'dt_order' => $dt_order, 'no_order' => $no_order, 'oid_paybill' => $oid_paybill, 'money_order' => $money_order, 'result_pay' => $result_pay, 'settle_date' => $settle_date, 'info_order' => $info_order, 'pay_type' => $pay_type, 'bank_code' => $bank_code, 'no_agree' => $no_agree, 'id_type' => $id_type, 'id_no' => $id_no, 'acct_name' => $acct_name);
if (!$this->getSignVeryfy($parameter, $sign)) {
return false;
}
return true;
}
示例7: verifyReturn
/**
* 针对return_url验证消息是否是连连支付发出的合法消息
* @return 验证结果
*/
function verifyReturn()
{
if (empty($_POST)) {
//判断POST来的数组是否为空
return false;
} else {
$res_data = $_POST["res_data"];
// file_put_contents("log.txt", "返回结果:" . $res_data . "\n", FILE_APPEND);
$json = new JSON();
//error_reporting(3);
//商户编号
$oid_partner = $json->decode($res_data)->{'oid_partner'};
//首先对获得的商户号进行比对
if (trim($oid_partner) != $this->llpay_config['oid_partner']) {
//商户号错误
return false;
}
//生成签名结果
$parameter = array('oid_partner' => $oid_partner, 'sign_type' => $json->decode($res_data)->{'sign_type'}, 'dt_order' => $json->decode($res_data)->{'dt_order'}, 'no_order' => $json->decode($res_data)->{'no_order'}, 'oid_paybill' => $json->decode($res_data)->{'oid_paybill'}, 'money_order' => $json->decode($res_data)->{'money_order'}, 'result_pay' => $json->decode($res_data)->{'result_pay'}, 'settle_date' => $json->decode($res_data)->{'settle_date'}, 'info_order' => $json->decode($res_data)->{'info_order'}, 'pay_type' => $json->decode($res_data)->{'pay_type'}, 'bank_code' => $json->decode($res_data)->{'bank_code'});
if (!$this->getSignVeryfy($parameter, $json->decode($res_data)->{'sign'})) {
return false;
}
return true;
}
}
示例8: readParameters
/**
* @see Page::readParameters()
*/
public function readParameters()
{
parent::readParameters();
if (!WCF::getUser()->getPermission('user.source.profiles.canManageProfiles')) {
throw new PermissionDeniedException();
}
if (isset($_POST['packages'])) {
$packages = JSON::decode($_POST['packages']);
if (!is_array($packages)) {
$this->sendResponse('pb.build.profile.error.packages.empty', true);
}
$this->packages = $packages;
}
if (isset($_POST['packageHash'])) {
$this->packageHash = StringUtil::trim($_POST['packageHash']);
}
if (isset($_POST['packageName'])) {
$this->packageName = StringUtil::trim($_POST['packageName']);
}
if (isset($_POST['profileName'])) {
$this->profileName = StringUtil::trim($_POST['profileName']);
if (empty($this->profileName)) {
$this->sendResponse('wcf.global.error.empty', true);
}
}
if (isset($_POST['resource'])) {
$this->resource = StringUtil::trim($_POST['resource']);
}
}
示例9: getUser
/**
* Retrieve the user's data
*
* The array needs to contain at least 'user', 'email', 'name' and optional 'grps'
*
* @return array
*/
public function getUser()
{
$JSON = new \JSON(JSON_LOOSE_TYPE);
$data = array();
$result = $JSON->decode($this->oAuth->request('user'));
$data['user'] = $result['login'];
$data['name'] = $result['name'];
$result = $JSON->decode($this->oAuth->request('user/emails'));
foreach ($result as $row) {
if ($row['primary']) {
$data['mail'] = $row['email'];
break;
}
}
return $data;
}
示例10: exchange_shop_license
/**
* 功能:与 ECShop 交换数据
*
* @param array $certi 登录参数
* @param array $license 网店license信息
* @param bool $use_lib 使用哪一个json库,0为ec,1为shopex
* @return array
*/
function exchange_shop_license($certi, $license, $use_lib = 0)
{
if (!is_array($certi)) {
return array();
}
include_once ROOT_PATH . 'includes/cls_transport.php';
include_once ROOT_PATH . 'includes/cls_json.php';
$params = '';
foreach ($certi as $key => $value) {
$params .= '&' . $key . '=' . $value;
}
$params = trim($params, '&');
$transport = new transport();
//$transport->connect_timeout = 1;
$request = $transport->request($license['certi'], $params, 'POST');
$request_str = json_str_iconv($request['body']);
if (empty($use_lib)) {
$json = new JSON();
$request_arr = $json->decode($request_str, 1);
} else {
include_once ROOT_PATH . 'includes/shopex_json.php';
$request_arr = json_decode($request_str, 1);
}
return $request_arr;
}
示例11: send
/**
* 与远程服务器发送数据
* @param string $query 查询字符串
* @return array
*/
private static function send($query = '')
{
$url = self::UPDATE_URL . $query;
if (($return = file_get_contents($url)) && ($return = JSON::decode($return))) {
return $return;
}
}
示例12: line
/**
* @brief 获取物流轨迹线路
* @param $ShipperCode string 物流公司代号
* @param $LogisticCode string 物流单号
* @return string array 轨迹数据
*/
public function line($ShipperCode, $LogisticCode)
{
$params = array('ShipperCode' => $ShipperCode, 'LogisticCode' => $LogisticCode);
$sendData = JSON::encode($params);
$curlData = array('RequestData' => $sendData, 'EBusinessID' => $this->appid, 'RequestType' => '1002', 'DataType' => 2, 'DataSign' => base64_encode(md5($sendData . $this->appkey)));
$result = $this->curlSend($this->getSubmitUrl(), $curlData);
return $this->response(JSON::decode($result));
}
示例13: loadCBData
/**
* Read config
*
* @return bool|mixed
*/
protected function loadCBData()
{
$json = new JSON(JSON_LOOSE_TYPE);
$file = @file_get_contents(DOKU_PLUGIN . "custombuttons/config.json");
if (!$file) {
return false;
}
return $json->decode($file);
}
示例14: authorstatsReadJSON
function authorstatsReadJSON()
{
$json = new JSON(JSON_LOOSE_TYPE);
$file = @file_get_contents(DOKU_PLUGIN . "authorstats/authorstats.json");
if (!$file) {
return array();
}
return $json->decode($file);
}
示例15: validate
/**
* @param string $data
* @param string $headstr
* @return \stdClass|false
*/
public function validate($data, $headstr)
{
sscanf($headstr, "sha1=%s", $headsig);
if (hash_equals(hash_hmac('sha1', $data, self::$secret), $headsig)) {
return \JSON::decode($data);
} else {
return false;
}
}