本文整理汇总了PHP中JSON::unserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::unserialize方法的具体用法?PHP JSON::unserialize怎么用?PHP JSON::unserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSON
的用法示例。
在下文中一共展示了JSON::unserialize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: to_array
public static function to_array($var)
{
if (!$var) {
return array();
}
if (is_array($var)) {
return $var;
}
if (is_object($var) && get_class($var) == 'stdClass') {
$array = array();
foreach ($var as $key => $value) {
$array[$key] = $value;
}
return $array;
}
if (is_object($var) && method_exists($var, '__toJSON')) {
return JSON::unserialize($var->__toJSON());
}
if (is_object($var) && method_exists($var, 'to_array')) {
return $var->to_array();
}
if (is_object($var) && method_exists($var, 'toArray')) {
return $var->toArray();
}
return array();
}
示例2: parseJSON
private function parseJSON($json)
{
if (!extension_loaded('json')) {
include_once dirname(__FILE__) . '/JSON.class.php';
$json = new JSON();
$objs = $json->unserialize($json);
} else {
$objs = json_decode($json);
}
return $objs;
}
示例3: plan_process_oembed
function plan_process_oembed($urls)
{
include_once 'json.php';
foreach ($urls as $url) {
$url = strip_tags(trim($url));
$data = file_get_contents("http://oohembed.com/oohembed/?url={$url}");
$json = new JSON();
$embed = $json->unserialize($data);
return $embed->html;
}
// else return $url;
}
示例4: unserialize
public static function unserialize($var)
{
$json = array();
if (!is_array($var) && !(is_object($var) && get_class($var) == 'stdClass')) {
$var = json_decode($var);
}
if (is_array($var)) {
foreach ($var as $key => $value) {
$json[$key] = $value;
}
} else {
if (is_object($var) && get_class($var) == 'stdClass') {
foreach ($var as $key => $value) {
$json[$key] = $value;
}
}
}
foreach ($json as $key => $value) {
if (is_array($value) || is_object($value) && get_class($value) == 'stdClass') {
$json[$key] = JSON::unserialize($value);
}
}
return $json;
}
示例5: JSON
function dsq_json_decode($data)
{
$json = new JSON();
return $json->unserialize($data);
}
示例6: executeTokens
private function executeTokens($text){
$regex = "/{JoooidContent[\w\ \?\=,\/\.:\"\&\-]*}/i";
$val = 0;
$val = preg_match($regex, $text,$matches);
if ($val > 0 ) {
$document =& JFactory::getDocument();
$document->addScript("https://maps.google.com/maps/api/js?sensor=true");
$document->addScript("components/com_joooid/assets/api.js");
$document->addScript("components/com_joooid/assets/JoooidRpc.js");
$document->addScript("components/com_joooid/assets/rpc.js");
}
while ($val!=0){
$stringa =str_replace("JoooidContent","", $matches[0]);
$jsonObj = new JSON;
$json = $jsonObj->unserialize($stringa);
if (!isset($json->type)) {
$text = preg_replace($regex,str_replace("JoooidContent","TYPEERRORJoooidContent",$matches[0]),$text);
$val = preg_match($regex, $text,$matches);
continue;
}
$obj = $this->createParamsArr($json->type,$json);
if ($obj == null){
$text = preg_replace($regex,str_replace("JoooidContent","ERRORJoooidContent",$matches[0]),$text);
$val = preg_match($regex, $text,$matches);
continue;
}
$html = $obj->render();
$text = str_replace($matches[0],$html,$text);
$val = preg_match($regex, $text,$matches);
}
$subst = preg_replace ("/{ERRORJoooidContent/", "{JoooidContent",$text);
$text = $subst;
// matches[0]: original token
// matches[1]: type
// matches[2]: parameters
return $text;
}
示例7: test_json
public function test_json()
{
$subjects = array("[1, 2, 3]", "{foo: 'bar'}", "{foo: 'bar', 1: true, 2: false, 3: nil, 4: [1, 2, 3]}");
foreach ($subjects as $v) {
$json = new JSON();
$this->assertEquals($json->unserialize($v), json_decode($v));
}
}
示例8: cp_calculatedfieldsf_get_option
function cp_calculatedfieldsf_get_option($field, $default_value, $id = '')
{
$value = '';
if (!defined("CP_CALCULATEDFIELDSF_ID")) {
define("CP_CALCULATEDFIELDSF_ID", 1);
}
if ($id == '') {
$id = CP_CALCULATEDFIELDSF_ID;
}
global $wpdb, $cp_calculatedfieldsf_option_buffered_item, $cp_calculatedfieldsf_option_buffered_id;
if ($cp_calculatedfieldsf_option_buffered_id == $id) {
if (property_exists($cp_calculatedfieldsf_option_buffered_item, $field)) {
$value = @$cp_calculatedfieldsf_option_buffered_item->{$field};
}
} else {
$myrows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . CP_CALCULATEDFIELDSF_FORMS_TABLE . " WHERE id=%d", $id));
if (!empty($myrows)) {
if (property_exists($myrows[0], $field)) {
$value = @$myrows[0]->{$field};
} else {
$value = $default_value;
}
$cp_calculatedfieldsf_option_buffered_item = $myrows[0];
$cp_calculatedfieldsf_option_buffered_id = $id;
} else {
$value = $default_value;
}
}
if ($field == 'form_structure' && !is_array($value)) {
$raw_form_str = cp_calculatedfieldsf_cleanJSON($value);
$form_data = json_decode($raw_form_str);
if (is_null($form_data)) {
$json = new JSON();
$form_data = $json->unserialize($raw_form_str);
}
$value = $cp_calculatedfieldsf_option_buffered_item->form_structure = !is_null($form_data) ? $form_data : '';
}
if ($field == 'vs_all_texts' && empty($value) || $value == '' && $cp_calculatedfieldsf_option_buffered_item->form_structure == '') {
$value = $default_value;
}
/**
* Filters applied before returning a form option,
* use three parameters: The value of option, the name of option and the form's id
* returns the new option's value
*/
$value = apply_filters('cpcff_get_option', $value, $field, $id);
return $value;
}
示例9: upgradeCheck
private function upgradeCheck($module)
{
global $cookie;
$ps_version = floatval(substr(_PS_VERSION_, 0, 3));
// Only run upgrae check if module is loaded in the backoffice.
if ($ps_version > 1.1 && $ps_version < 1.5 && (!is_object($cookie) || !$cookie->isLoggedBack())) {
return;
}
if ($ps_version >= 1.5) {
$context = Context::getContext();
if (!isset($context->employee) || !$context->employee->isLoggedBack()) {
return;
}
}
// Get Presto-Changeo's module version info
$mod_info_str = Configuration::get('PRESTO_CHANGEO_SV');
if (!function_exists('json_decode')) {
if (!file_exists(dirname(__FILE__) . '/JSON.php')) {
return false;
}
include_once dirname(__FILE__) . '/JSON.php';
$j = new JSON();
$mod_info = $j->unserialize($mod_info_str);
} else {
$mod_info = json_decode($mod_info_str);
}
// Get last update time.
$time = time();
// If not set, assign it the current time, and skip the check for the next 7 days.
if ($this->_last_updated <= 0) {
Configuration::updateValue('PRESTO_CHANGEO_UC', $time);
$this->_last_updated = $time;
}
// If haven't checked in the last 1-7+ days
$update_frequency = max(86400, isset($mod_info->{$module}->{'T'}) ? $mod_info->{$module}->{'T'} : 86400);
if ($this->_last_updated < $time - $update_frequency) {
// If server version number exists and is different that current version, return URL
if (isset($mod_info->{$module}->{'V'}) && $mod_info->{$module}->{'V'} > $this->_full_version) {
return $mod_info->{$module}->{'U'};
}
$url = 'http://updates.presto-changeo.com/?module_info=' . $module . '_' . $this->version . '_' . $this->_last_updated . '_' . $time . '_' . $update_frequency;
$mod = @file_get_contents($url);
if ($mod == '' && function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$mod = curl_exec($ch);
}
Configuration::updateValue('PRESTO_CHANGEO_UC', $time);
$this->_last_updated = $time;
if (!function_exists('json_decode')) {
$j = new JSON();
$mod_info = $j->unserialize($mod);
} else {
$mod_info = json_decode($mod);
}
if (!isset($mod_info->{$module}->{'V'})) {
return false;
}
if (Validate::isCleanHtml($mod)) {
Configuration::updateValue('PRESTO_CHANGEO_SV', $mod);
}
if ($mod_info->{$module}->{'V'} > $this->_full_version) {
return $mod_info->{$module}->{'U'};
} else {
return false;
}
} elseif (isset($mod_info->{$module}->{'V'}) && $mod_info->{$module}->{'V'} > $this->_full_version) {
return $mod_info->{$module}->{'U'};
} else {
return false;
}
}
示例10: plugins_url
}
?>
<link href="<?php
echo plugins_url('css/stylepublic.css', __FILE__);
?>
" type="text/css" rel="stylesheet" />
<link href="<?php
echo plugins_url('css/cupertino/jquery-ui-1.8.20.custom.css', __FILE__);
?>
" type="text/css" rel="stylesheet" />
<?php
$raw_form_str = str_replace("\r", " ", str_replace("\n", " ", cp_calculatedfieldsf_cleanJSON(cp_calculatedfieldsf_get_option('form_structure', CP_CALCULATEDFIELDSF_DEFAULT_form_structure, $id))));
$form_data = json_decode($raw_form_str);
if (is_null($form_data)) {
$json = new JSON();
$form_data = $json->unserialize($raw_form_str);
}
if (!is_null($form_data) && isset($form_data[1]) && isset($form_data[1][0]) && isset($form_data[1][0]->formtemplate)) {
$templatelist = cp_calculatedfieldsf_available_templates();
if (isset($templatelist[$form_data[1][0]->formtemplate])) {
print '<link href="' . esc_attr(esc_url($templatelist[$form_data[1][0]->formtemplate]['file'])) . '" type="text/css" rel="stylesheet" />';
if (isset($templatelist[$form_data[1][0]->formtemplate]['js'])) {
print '<script src="' . esc_attr(esc_url($templatelist[$form_data[1][0]->formtemplate]['js'])) . '"></script>';
}
}
}
$raw_form_str = str_replace('"', '"', esc_attr($raw_form_str));
?>
<form name="cp_calculatedfieldsf_pform<?php
echo $CP_CFF_global_form_count;
?>
示例11: doJsonDecode
/**
* @param $sData
*
* @return array|mixed
*/
public function doJsonDecode($sData)
{
if (function_exists('json_decode')) {
return json_decode($sData);
}
if (!class_exists('JSON')) {
require_once dirname(__FILE__) . ICWP_DS . 'json/JSON.php';
}
$oJson = new JSON();
return @$oJson->unserialize($sData);
}