本文整理汇总了PHP中Services_JSON::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Services_JSON::decode方法的具体用法?PHP Services_JSON::decode怎么用?PHP Services_JSON::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Services_JSON
的用法示例。
在下文中一共展示了Services_JSON::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function json_decode($arg, $is_array = true)
{
global $services_json;
if (!isset($services_json)) {
$services_json = new Services_JSON();
}
return $is_array ? get_object_vars($services_json->decode($arg)) : $services_json->decode($arg);
}
示例2: loginTeacher
static function loginTeacher($class, $pass, $ignoreNonexistent = false)
{
$json = new Services_JSON();
if (!$class) {
return "クラス名を入力してください。";
}
if (!$pass) {
return "パスワードを入力してください。";
}
if (!file_exists("fs/home/{$class}") && !$ignoreNonexistent) {
return "存在しないクラスIDが入力されています。";
}
if (preg_match('/^[a-zA-Z0-9\\-_]+$/', $pass)) {
$fp = fopen("user/list.txt", "r");
while ($line = fgets($fp)) {
$classlist = $json->decode($line);
if ($classlist["classid"] == $class) {
break;
}
}
fclose($fp);
if (isset($classlist) && $classlist["pass"] == $pass) {
// Success
MySession::set("class", $class);
MySession::set("user", self::TEACHER);
setcookie("class", $class, time() + 60 * 60 * 24 * 30);
return true;
} else {
return "クラスIDかパスワードが間違っています。";
}
} else {
return "パスワードは半角英数とハイフン、アンダースコアだけが使えます。";
}
}
示例3: smarty_function_json
/**
* Smarty {json} plugin
*
* Type: function
* Name: json
* Purpose: fetch json file and assign result as a template variable (array)
* @param url (url to fetch)
* @param assign (element to assign to)
* @return array|null if the assign parameter is passed, Smarty assigns the
* result to a template variable
*/
function smarty_function_json($params, &$smarty)
{
if (empty($params['url'])) {
$smarty->_trigger_fatal_error("[json] parameter 'url' cannot be empty");
return;
}
$content = array();
$data = file_get_contents($params['url']);
if (empty($data)) {
return false;
}
if (!is_callable('json_decode')) {
require_once 'JSON.php';
$json = new Services_JSON();
$content = $json->decode(trim(file_get_contents($params['url'])));
} else {
$content = json_decode(trim(file_get_contents($params['url'])));
}
if ($params['debug'] === true) {
echo "<pre>";
print_r($content);
echo "</pre>";
}
if (!empty($params['assign'])) {
$smarty->assign($params['assign'], $content);
} else {
return $content;
}
}
示例4: __construct
public function __construct($result, $httpStatusCode, $request)
{
if (function_exists('json_decode')) {
$this->body = json_decode($result, true);
} else {
require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->body = $json->decode($result);
}
$this->httpStatusCode = $httpStatusCode;
// If there is an error we want to build out an error string.
if ($this->httpStatusCode !== 200) {
$this->error = $this->body['error'];
$this->errorMessage = $this->error . ': ' . $this->body['description'];
if (array_key_exists('issues', $this->body)) {
$this->errorIssues = $this->body['issues'];
foreach ($this->errorIssues as &$issue) {
$this->errorMessage .= array_search($issue, $this->errorIssues) . ': ' . $issue;
}
unset($issue);
}
}
if (array_key_exists('request', $this->body)) {
$this->request = $this->body['request'];
} else {
$this->request = null;
}
$this->request = $request;
$this->result = $result;
}
示例5: explode
function get_tree_html($jsontree)
{
$this->EE->output->enable_profiler(FALSE);
$cpurl = $this->EE->config->item('cp_url');
$pieces = explode("/", $cpurl);
$cpurl_index = $pieces[count($pieces) - 1];
$jsontree = str_replace("'", '"', (string) $jsontree);
$jsontree = $this->my_strip_tags($jsontree);
//$jsontree = str_replace('EDIT', '', $jsontree);
$jsontree = str_replace('DELETE', '', $jsontree);
$jsontree = str_replace(' ', '', $jsontree);
$json = new Services_JSON();
$json_decoded = $json->decode($jsontree);
$navhtml = '';
foreach ($json_decoded as $item) {
$id = isset($item->id) ? $item->id : '';
$className = isset($item->className) ? $item->className : '';
$navhtml .= '<li class="' . $className . '" id="' . $id . '" ><a href="' . $item->url . '" class="first_level">' . str_replace("http://", "", str_replace($_SERVER['HTTP_HOST'], "", str_replace('"', '\\"', $item->title))) . '</a>';
$navhtml .= $this->get_tree_ul($item);
$navhtml .= '</li>';
}
$navhtml = str_replace('[IMG]', '<img src="', $navhtml);
$navhtml = str_replace('[/IMG]', '"/>', $navhtml);
return $navhtml;
}
示例6: diffapplydiff
function diffapplydiff($base, $diff)
{
if (function_exists('json_encode')) {
$diffs = json_decode($diff);
} else {
require_once "JSON.php";
$jsonser = new Services_JSON();
return $jsonser->decode($diff);
}
for ($i = count($diffs) - 1; $i >= 0; $i--) {
if ($diffs[$i][0] == 2) {
//replace
array_splice($base, $diffs[$i][1], $diffs[$i][2], $diffs[$i][3]);
} else {
if ($diffs[$i][0] == 0) {
//insert
array_splice($base, $diffs[$i][1], 0, $diffs[$i][2]);
} else {
if ($diffs[$i][0] == 1) {
//delete
array_splice($base, $diffs[$i][1], $diffs[$i][2]);
}
}
}
}
return $base;
}
示例7: display
function display($persona)
{
$json = new Services_JSON();
$persona->get_configuration_data();
$properties =& PersonaProperty::load_persona_properties($persona->persona_id);
$propertyCount = count($properties);
// echo "<pre>" . print_r($persona, true) . "</pre>";
if (!$propertyCount) {
echo "No status info available";
} else {
foreach ($properties as $k => $property) {
if ($property->name == 'Status') {
$content = $json->decode($property->content);
if ($content->friendly) {
echo $content->friendly;
echo '<br />';
echo 'Last fetch on: ' . date("H:i D jS M", strtotime($content->date));
} else {
echo "No status info available";
}
/*
echo '<!-- ' . "\n";
echo print_r($property, true) . "\n";
echo print_r($content, true) . "\n";
echo ' -->';
*/
}
}
}
}
示例8: json
function json($file)
{
global $fs, $word, $around;
$j = new Services_JSON();
$a = explode("T", $word);
$date = preg_replace("/-/", "/", $a[0]);
$time = $a[1];
echo "{$time} --- {$date}<BR>";
$lines = explode("\n", $fs->getContent("{$file}-data.log"));
$a = array();
$around = $around / 10;
$found = false;
foreach ($lines as $line) {
$e = $j->decode($line);
if ($e) {
$a[] = toHTML($e);
//echo $e["date"]." ".$e["time"]. "<BR>";
if ($found) {
if (count($a) > $around * 2) {
break;
}
} else {
if (count($a) > $around) {
array_shift($a);
}
if ($e["date"] == $date && $e["time"] == $time) {
array_push($a, "<a name='center'/><font color=red>-----------------------------------</font><BR>");
$found = TRUE;
}
}
}
}
print join("<BR>", $a);
}
示例9: __construct
public function __construct($result, $httpStatusCode, $request)
{
$this->body = null;
$this->apiStatus = null;
$this->apiErrorMessage = null;
if (function_exists('json_decode')) {
$this->body = json_decode($result, true);
} else {
require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->body = $json->decode($result);
}
$this->httpStatusCode = $httpStatusCode;
$this->request = $request;
$this->rawResponse = $result;
// Only attempt to get our response body if the http status code expects a body
if (!in_array($this->httpStatusCode, array(204, 304))) {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->body = $json->decode($result);
// NOTE: Responses from /v3 endpoints don't contain status or error_message.
if (array_key_exists('status', $this->body)) {
$this->apiStatus = intval($this->body['status']);
}
if (array_key_exists('error_message', $this->body)) {
$this->apiErrorMessage = $this->body['error_message'];
}
}
}
示例10: loadJSON
/**
* Load les infos depuis une string JSON
*
* @access public
* @param string $json La string JSON
* @return TafelTree Le TafelTree créé
*/
public function loadJSON($json, $id, $imgs = 'imgs/', $width = '100%', $height = 'auto', $options = array())
{
$tree = new TafelTree($id, $imgs, $width, $height, $options);
$service = new Services_JSON();
$tree->items = TafelTree::loadServiceJSON($service->decode($json));
return $tree;
}
示例11: fwrite
function make_short_url($restURL)
{
$out = "GET " . $restURL . " HTTP/1.1\r\n";
$out .= "Host: api.bit.ly\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n\r\n";
$handle = @fsockopen('api.bit.ly', 80, $errno, $errstr, 30);
fwrite($handle, $out);
$body = false;
$contents = '';
while (!feof($handle)) {
$return = fgets($handle, 1024);
if ($body) {
$contents .= $return;
}
if ($return == "\r\n") {
$body = true;
}
}
fclose($handle);
$json = new Services_JSON();
$data = $json->decode($contents);
//for issues with unable to authenticate error, somehow they return errors instead of error.
if (!isset($data->status_code)) {
return false;
}
if ($data->status_code != '200') {
return false;
}
return $data->data->url;
}
示例12: getFiltersFor
function getFiltersFor($msg, $id = null)
{
$json = new Services_JSON();
if ($id !== null) {
$this->id = $id;
}
$this->find();
$res = array();
while ($this->fetch()) {
$fltrs = $json->decode($this->filter);
// Serach for "from" and "subject"
foreach ($fltrs as $f) {
$from = !isset($f->from) || trim($f->from) == "";
$subj = !isset($f->subject) || trim($f->subject) == "";
if ($from && $subj) {
continue;
}
if (!$from) {
$from = strpos($msg->from, $f->from) !== false;
}
if (!$subj) {
$subj = strpos($msg->subject, $f->subject) !== false;
}
if ($from && $subj) {
$res[] = $this->toArray();
break;
}
}
}
return $res;
}
示例13: decode
function decode($str)
{
//$lib='native';
// $lib='services_JSON';
// $lib='jsonrpc';
// dirty trick to correct bad json for photos
//$str = preg_replace('/\t} {/','}, {', $str);
// remove trailing ,
//$str = preg_replace('/,[ \r\n\t]+}/',' }', $str);
// echo "Using $lib<BR>";
// echo $str;
if (function_exists('json_decode') && JSON_LIB_DECODE == 'native') {
$arr = json_decode($str, true);
} else {
if (JSON_LIB_DECODE == 'services_JSON') {
require_once dirname(__FILE__) . '/json.php';
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$arr = $json->decode($str);
} else {
if (JSON_LIB_DECODE == 'jsonrpc') {
require_once dirname(__FILE__) . '/jsonrpc/xmlrpc.php';
require_once dirname(__FILE__) . '/jsonrpc/jsonrpc.php';
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
//require_once dirname(__FILE__).'/jsonrpc/json_extension_api.php';
//$arr=json_decode($str, true);
$value = php_jsonrpc_decode_json($str);
if ($value) {
$arr = php_jsonrpc_decode($value, array());
}
}
}
}
// print_r($arr);
return $arr;
}
示例14: decode
/**
* Transforma el texto enviado en formato JSON a un objeto PHP
*
* @param string $html texto JSON a decodear
* @return object objeto PHP
*/
public function decode($html)
{
// include_once("classes/JSON.class.php");
$json = new Services_JSON();
$data = stripslashes($html);
return $json->decode($data);
}
示例15:
function json_decode($jsonString) {
static $jsonobj;
if (!isset($jsonobj)) {
include_once (IA_ROOT . '/source/library/json/JSON.php');
$jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
}
return $jsonobj->decode($jsonString);
}