当前位置: 首页>>代码示例>>PHP>>正文


PHP JSON::encode方法代码示例

本文整理汇总了PHP中JSON::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::encode方法的具体用法?PHP JSON::encode怎么用?PHP JSON::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSON的用法示例。


在下文中一共展示了JSON::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: display

 function display()
 {
     global $app_strings, $current_user, $mod_strings, $theme, $beanList, $beanFiles;
     $smarty = new Sugar_Smarty();
     $json = new JSON();
     require_once 'include/JSON.php';
     //Load the field list from the target module
     if (!empty($_REQUEST['targetModule']) && $_REQUEST['targetModule'] != 'undefined') {
         $module = $_REQUEST['targetModule'];
         if (isset($_REQUEST['package']) && $_REQUEST['package'] != 'studio' && $_REQUEST['package'] != '') {
             //Get the MB Parsers
             require_once 'modules/ModuleBuilder/MB/MBPackage.php';
             $pak = new MBPackage($_REQUEST['package']);
             $defs = $pak->modules[$module]->getVardefs();
             $fields = FormulaHelper::cleanFields(array_merge($pak->modules[$module]->getLinkFields(), $defs['fields']));
         } else {
             $seed = BeanFactory::getBean($module);
             $fields = FormulaHelper::cleanFields($seed->field_defs);
         }
         $smarty->assign('Field_Array', $json->encode($fields));
     } else {
         $fields = array(array('income', 'number'), array('employed', 'boolean'), array('first_name', 'string'), array('last_name', 'string'));
         $smarty->assign('Field_Array', $json->encode($fields));
     }
     if (!empty($_REQUEST['targetField'])) {
         $smarty->assign("target", $_REQUEST['targetField']);
     }
     if (isset($_REQUEST['returnType'])) {
         $smarty->assign("returnType", $_REQUEST['returnType']);
     }
     //Assign any requested Javascript event actions
     foreach (array('onSave', 'onLoad', 'onClose') as $e) {
         if (!empty($_REQUEST[$e])) {
             $smarty->assign($e, html_entity_decode($_REQUEST[$e], ENT_QUOTES));
         } else {
             $smarty->assign($e, 'function(){}');
         }
     }
     //Check if we need to load Ext ourselves
     if (!isset($_REQUEST['loadExt']) || $_REQUEST['loadExt'] && $_REQUEST['loadExt'] != "false") {
         $smarty->assign('loadExt', true);
     } else {
         $smarty->assign('loadExt', false);
     }
     if (!empty($_REQUEST['formula'])) {
         $smarty->assign('formula', $json->decode(htmlspecialchars_decode($_REQUEST['formula'])));
     }
     if (isset($_REQUEST['returnType'])) {
         $smarty->assign('returnType', $_REQUEST['returnType']);
     }
     $smarty->assign('app_strings', $app_strings);
     $smarty->assign('mod', $mod_strings);
     $smarty->display('modules/ExpressionEngine/tpls/formulaBuilder.tpl');
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:54,代码来源:view.editformula.php

示例2: action_index

 public function action_index()
 {
     try {
         if ($token = $this->grantAccessToken()) {
             // @see http://tools.ietf.org/html/rfc6749#section-5.1
             // server MUST disable caching in headers when tokens are involved
             $this->response->status(200);
             $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
             $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
             $this->response->body(JSON::encode($token));
             return;
         }
     } catch (Oauth2_Exception $e) {
         // Throw an exception because there was a problem with the client's request
         $response = array('error' => $e->getError(), 'error_description' => $e->getMessage());
         $this->response->status($e->getCode());
         $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
         $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
         $this->response->body(json_encode($response));
         return;
     } catch (Exception $e) {
         /**
          * Something went wrong!
          *
          * Throw an error when a non-library specific exception has been thrown
          *
          * You should probably show a nice error page :)
          *
          * Do NOT redirect the user back to the client.
          */
         throw HTTP_Exception::factory(500, $e->getMessage());
     }
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:33,代码来源:token.php

示例3: action_tag

 /**
  * Retrieve a JSON object containing autocomplete suggestions for existing users.
  */
 public function action_tag()
 {
     $string = $this->request->param('string', FALSE);
     $type = $this->request->param('type', 'blog');
     // The user enters a comma-separated list of tags. We only autocomplete the last tag.
     $tags_typed = Tags::explode($string);
     $tag_last = UTF8::strtolower(array_pop($tags_typed));
     $matches = array();
     if (!empty($tag_last)) {
         $query = DB::select('name')->from('tags')->where('name', 'LIKE', $tag_last . '%')->where('type', '=', $type);
         // Do not select already entered terms.
         if (!empty($tags_typed)) {
             $query->where('name', 'NOT IN', $tags_typed);
         }
         $result = $query->limit('10')->execute();
         $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
         foreach ($result as $tag) {
             $n = $tag['name'];
             // Tag names containing commas or quotes must be wrapped in quotes.
             if (strpos($tag['name'], ',') !== FALSE or strpos($tag['name'], '"') !== FALSE) {
                 $n = '"' . str_replace('"', '""', $tag['name']) . '"';
             } else {
                 $matches[$prefix . $n] = Text::plain($tag['name']);
             }
         }
     }
     $this->response->body(JSON::encode($matches));
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:31,代码来源:autocomplete.php

示例4: cleanID

 function handle_ajax_call(&$event, $param)
 {
     if ($event->data == 'plugin_do') {
         $id = cleanID($_REQUEST['do_page']);
         if (auth_quickaclcheck($id) < AUTH_EDIT) {
             echo -1;
             $event->preventDefault();
             $event->stopPropagation();
             return false;
         }
         // toggle status of a single task
         $hlp = plugin_load('helper', 'do');
         $status = $hlp->toggleTaskStatus($id, $_REQUEST['do_md5'], $_REQUEST['do_commit']);
         // rerender the page
         p_get_metadata(cleanID($_REQUEST['do_page']), '', true);
         header('Content-Type: text/plain; charset=utf-8');
         echo $status;
         $event->preventDefault();
         $event->stopPropagation();
         return false;
     } elseif ($event->data == 'plugin_do_status') {
         // read status for a bunch of tasks
         require_once DOKU_INC . 'inc/JSON.php';
         $JSON = new JSON();
         $hlp = plugin_load('helper', 'do');
         $status = $hlp->getAllPageStatuses(cleanID($_REQUEST['do_page']));
         $status = $JSON->encode($status);
         header('Content-Type: text/plain; charset=utf-8');
         echo $status;
         $event->preventDefault();
         $event->stopPropagation();
         return false;
     }
     return true;
 }
开发者ID:rauschen,项目名称:do,代码行数:35,代码来源:action.php

示例5: display

 function display()
 {
     global $app_strings, $current_user, $mod_strings, $app_list_strings;
     $smarty = new Sugar_Smarty();
     require_once 'include/JSON.php';
     //Load the field list from the target module
     $selected_lang = $_SESSION['authenticated_user_language'];
     $vardef = array();
     //Copy app strings
     $my_list_strings = array_merge($app_list_strings);
     $child = $_REQUEST['field'];
     //if we are using ModuleBuilder then process the following
     if (!empty($_REQUEST['package']) && $_REQUEST['package'] != 'studio') {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $this->module = $mb->getPackageModule($_REQUEST['package'], $_REQUEST['view_module']);
         $vardef = $this->module->getVardefs();
         $this->module->mblanguage->generateAppStrings(false);
         $my_list_strings = array_merge($my_list_strings, $this->module->mblanguage->appListStrings[$selected_lang . '.lang.php']);
     } else {
         $vardef = BeanFactory::getBean($_REQUEST['view_module'])->field_defs;
     }
     foreach ($my_list_strings as $key => $value) {
         if (!is_array($value)) {
             unset($my_list_strings[$key]);
         }
     }
     $parents = $this->getParentDDs($vardef, $child, $my_list_strings);
     $visibility_grid = !empty($vardef[$child]['visibility_grid']) ? $vardef[$child]['visibility_grid'] : array();
     $smarty->assign('app_strings', $app_strings);
     $smarty->assign('mod', $mod_strings);
     $smarty->assign('parents', JSON::encode($parents));
     $smarty->assign('visibility_grid', JSON::encode($visibility_grid));
     $smarty->display('modules/ExpressionEngine/tpls/ddEditor.tpl');
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:35,代码来源:view.editDepDropdown.php

示例6: testEncoding

 public function testEncoding()
 {
     $formatter = new JSON();
     $data = array('name' => 'Joe', 'age' => 21, 'employed' => true);
     $options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null;
     $this->assertSame(json_encode($data, $options), $formatter->encode($data));
 }
开发者ID:gekt,项目名称:www,代码行数:7,代码来源:JSONTest.php

示例7: array

 /**
  * Register the events
  *
  * @param $event DOKU event on ajax call
  * @param $param parameters, ignored
  */
 function _ajax_call(&$event, $param)
 {
     if ($event->data !== 'plugin_explorertree') {
         return;
     }
     //no other ajax call handlers needed
     $event->stopPropagation();
     $event->preventDefault();
     //e.g. access additional request variables
     global $INPUT;
     //available since release 2012-10-13 "Adora Belle"
     if (!checkSecurityToken()) {
         $data = array('error' => true, 'msg' => 'invalid security token!');
     } else {
         switch ($INPUT->str('operation')) {
             case 'explorertree_branch':
                 if (!($helper = plugin_load('helper', 'explorertree'))) {
                     $data = array('error' => true, 'msg' => "Can't load tree helper.");
                     break;
                 }
                 if (!($route = $helper->loadRoute($INPUT->str('route'), $INPUT->arr('loader')))) {
                     $data = array('error' => true, 'msg' => "Can't load route '" . $INPUT->str('route') . "'!");
                 }
                 $data = array('html' => $helper->htmlExplorer($INPUT->str('route'), ltrim(':' . $INPUT->str('itemid')), ':'));
                 if (!$data['html']) {
                     $data['error'] = true;
                     $data['msg'] = "Can't load tree html.";
                 }
                 break;
             case 'callback':
                 if (!($helper = plugin_load('helper', 'explorertree'))) {
                     $data = array('error' => true, 'msg' => "Can't load tree helper.");
                     break;
                 }
                 $route = $helper->loadRoute($INPUT->str('route'), $INPUT->arr('loader'));
                 if (!$route || !is_callable(@$route['callbacks'][$INPUT->str(event)])) {
                     $data = array('error' => true, 'msg' => "Can't load callback '" . $INPUT->str('event') . "'for '" . $INPUT->str('route') . "'!");
                 }
                 $data = @call_user_func_array($route['callbacks'][$INPUT->str(event)], array($INPUT->str('itemid')));
                 if (!is_array($data)) {
                     $data = array('error' => true, 'msg' => "Callback for '" . $INPUT->str('event') . "' does not exists!");
                 }
                 break;
             default:
                 $data = array('error' => true, 'msg' => 'Unknown operation: ' . $INPUT->str('operation'));
                 break;
         }
         //data
         //json library of DokuWiki
     }
     if (is_array($data)) {
         $data['token'] = getSecurityToken();
     }
     require_once DOKU_INC . 'inc/JSON.php';
     $json = new JSON();
     //set content type
     header('Content-Type: application/json');
     echo $json->encode($data);
     //		$this->get_helper()->check_meta_changes();
 }
开发者ID:Klap-in,项目名称:explorertree,代码行数:66,代码来源:action.php

示例8: respond

 /**
  * send the result back to the client and exit
  * @param mixed $result the result to send back to the client
  */
 protected function respond($result)
 {
     header('Content-Type: application/json');
     $json = new JSON();
     echo $json->encode($result);
     exit;
 }
开发者ID:roverrobot,项目名称:components,代码行数:11,代码来源:ajax.php

示例9: endpoint

 public function endpoint()
 {
     $provider = new MyOAuthProvider();
     //we need to disable a check if it is our first call to requesttoken.
     $c = strtolower($this->args('api_call'));
     if ($c == 'requesttoken') {
         $provider->oauth->isRequestTokenEndpoint(true);
         $this->set('provider', $provider);
     } elseif ($c == 'accesstoken') {
         $this->set('provider', $provider);
     }
     try {
         $provider->oauth->checkOAuthRequest();
         $calls = array('requesttoken', 'accesstoken', 'listqueues', 'queueinfo', 'createqueue', 'listjobs', 'jobinfo', 'grabjob', 'findnewjob', 'dropjob', 'canceljob', 'completejob', 'downloadedjob', 'createjob', 'updatejobprogress', 'listbots', 'botinfo', 'registerbot', 'updatebot');
         if (in_array($c, $calls)) {
             $fname = "api_{$c}";
             $data = $this->{$fname}();
         } else {
             throw new Exception("Specified api_call '{$c}' does not exist.");
         }
         $result = array('status' => 'success', 'data' => $data);
     } catch (Exception $e) {
         $result = array('status' => 'error', 'error' => $e->getMessage());
     }
     //add in our version.
     $result['_api_version'] = self::$api_version;
     echo JSON::encode($result);
     exit;
 }
开发者ID:ricberw,项目名称:BotQueue,代码行数:29,代码来源:apiv1.php

示例10: log

	function log($priority, $message, $file = null, $line = null, $e = null) {
		$schema = "DEFAULT";
		$table = "logs";
		$trace = "";
		if (!empty($e)) {
			$trace = $e->getTraceAsString();
		}
		if (is_object($message)) {
			$message = JSON::encode($message);
		}
		$now = new Date();
		$log = array();
		$log["priority"] = $priority;
		$log["message"] = $message;
		$log["trace"] = $trace;
		$log["file"] = $file;
		$log["line"] = $line;
		$log["createdBy"] = "SYS";
		$log["createdTime"] = $now;
		$log["updatedBy"] = "SYS";
		$log["updatedTime"] = $now;

		$driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER;
		$insert = new Insert($table, $log, $schema);
		$link = DB::connect();
		$success = mysql_query($insert->sql(), $link);
		if (!$success) {
			$result = Bean::invoke(String::camelize('_'.$driver.'_driver'), "error", array($schema));
			throw new Exception("Cannot persist object. ".$result);
		}
	}
开发者ID:reekoheek,项目名称:php-fw,代码行数:31,代码来源:Log.php

示例11: api_return

/**
 * API数据返回
 *
 * @access  public
 * @param   array
 * @return  void
 */
function api_return($api_data, $data)
{
    include_once 'includes/cls_json.php';
    $return_data = array('version' => 0.1, 'api_url' => 'good.php', 'api_data' => $api_data, 'error' => 0, 'data' => $return_data['data'] = $data ? $data : '');
    header('Content-type: application/json');
    die(JSON::encode($return_data));
}
开发者ID:jiusanzhou,项目名称:ecapi,代码行数:14,代码来源:good.php

示例12: output

function output($data)
{
    header("Content-Type:text/html; charset=utf-8");
    $r_type = intval($_REQUEST['r_type']);
    //返回数据格式类型; 0:base64;1;json_encode;2:array
    $data['act'] = ACT;
    $data['act_2'] = ACT_2;
    sql_check("wap");
    if ($r_type == 0) {
        require_once APP_ROOT_PATH . 'system/libs/json.php';
        $JSON = new JSON();
        print_r(base64_encode($JSON->encode($data)));
        //	echo base64_encode(json_encode($data));
    } else {
        if ($r_type == 1) {
            //echo APP_ROOT_PATH; exit;
            require_once APP_ROOT_PATH . 'system/libs/json.php';
            //echo 'ss';exit;
            $JSON = new JSON();
            print_r($JSON->encode($data));
            //print_r(json_encode($data));
        } else {
            if ($r_type == 2) {
                print_r($data);
            }
        }
    }
    exit;
}
开发者ID:myjavawork,项目名称:sanxin-fangwei,代码行数:29,代码来源:functions.php

示例13: js_out

/**
 * Output all needed JavaScript
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function js_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    // The generated script depends on some dynamic options
    $cache = new cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.js');
    $cache->_event = 'JS_CACHE_USE';
    // load minified version for some files
    $min = $conf['compress'] ? '.min' : '';
    // array of core files
    $files = array(DOKU_INC . "lib/scripts/jquery/jquery{$min}.js", DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', DOKU_INC . "lib/scripts/jquery/jquery-ui{$min}.js", DOKU_INC . "lib/scripts/fileuploader.js", DOKU_INC . "lib/scripts/fileuploaderextended.js", DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/tw-sack.js', DOKU_INC . 'lib/scripts/qsearch.js', DOKU_INC . 'lib/scripts/tree.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/drag.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/editor.js', DOKU_INC . 'lib/scripts/locktimer.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/compatibility.js', DOKU_INC . 'lib/scripts/behaviour.js', DOKU_INC . 'lib/scripts/page.js', tpl_incdir() . 'script.js');
    // add possible plugin scripts and userscript
    $files = array_merge($files, js_pluginscripts());
    if (isset($config_cascade['userscript']['default'])) {
        $files[] = $config_cascade['userscript']['default'];
    }
    $cache_files = array_merge($files, getConfigFiles('main'));
    $cache_files[] = __FILE__;
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    $cache_ok = $cache->useCache(array('files' => $cache_files));
    http_cached($cache->cache, $cache_ok);
    // start output buffering and build the script
    ob_start();
    // add some global variables
    print "var DOKU_BASE   = '" . DOKU_BASE . "';";
    print "var DOKU_TPL    = '" . tpl_basedir() . "';";
    // FIXME: Move those to JSINFO
    print "var DOKU_UHN    = " . (int) useHeading('navigation') . ";";
    print "var DOKU_UHC    = " . (int) useHeading('content') . ";";
    // load JS specific translations
    $json = new JSON();
    $lang['js']['plugins'] = js_pluginstrings();
    echo 'LANG = ' . $json->encode($lang['js']) . ";\n";
    // load toolbar
    toolbar_JSdefines('toolbar');
    // load files
    foreach ($files as $file) {
        echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
        js_load($file);
        echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
    }
    // init stuff
    if ($conf['locktime'] != 0) {
        js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")");
    }
    // init hotkeys - must have been done after init of toolbar
    # disabled for FS#1958    js_runonstart('initializeHotkeys()');
    // end output buffering and get contents
    $js = ob_get_contents();
    ob_end_clean();
    // compress whitespace and comments
    if ($conf['compress']) {
        $js = js_compress($js);
    }
    $js .= "\n";
    // https://bugzilla.mozilla.org/show_bug.cgi?id=316033
    http_cached_finish($cache->cache, $js);
}
开发者ID:nextghost,项目名称:dokuwiki,代码行数:65,代码来源:js.php

示例14: ajax

 /**
  * @param Doku_Event$event
  * @param $param
  */
 public function ajax(Doku_Event $event, $param)
 {
     if ($event->data !== 'bureaucracy_user_field') {
         return;
     }
     $event->stopPropagation();
     $event->preventDefault();
     $search = $_REQUEST['search'];
     /** @var DokuWiki_Auth_Plugin $auth */
     global $auth;
     $users = array();
     foreach ($auth->retrieveUsers() as $username => $data) {
         if ($search === '' || stripos($username, $search) === 0 || stripos($data['name'], $search) !== false) {
             // Full name
             $users[$username] = $data['name'];
         }
         if (count($users) === 10) {
             break;
         }
     }
     if (count($users) === 1 && key($users) === $search) {
         $users = array();
     }
     require_once DOKU_INC . 'inc/JSON.php';
     $json = new JSON();
     echo $json->encode($users);
 }
开发者ID:rusidea,项目名称:analitika,代码行数:31,代码来源:action.php

示例15: handle_ajax

 /**
  * Step up
  *
  * @param Doku_Event $event
  */
 public function handle_ajax(Doku_Event $event)
 {
     if ($event->data != 'plugin_move_progress') {
         return;
     }
     $event->preventDefault();
     $event->stopPropagation();
     global $INPUT;
     global $USERINFO;
     if (!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
         http_status(403);
         exit;
     }
     $return = array('error' => '', 'complete' => false, 'progress' => 0);
     /** @var helper_plugin_move_plan $plan */
     $plan = plugin_load('helper', 'move_plan');
     if (!$plan->isCommited()) {
         // There is no plan. Something went wrong
         $return['complete'] = true;
     } else {
         $todo = $plan->nextStep($INPUT->bool('skip'));
         $return['progress'] = $plan->getProgress();
         $return['error'] = $plan->getLastError();
         if ($todo === 0) {
             $return['complete'] = true;
         }
     }
     $json = new JSON();
     header('Content-Type: application/json');
     echo $json->encode($return);
 }
开发者ID:kochichi,项目名称:dokuwiki-plugin-move,代码行数:36,代码来源:progress.php


注:本文中的JSON::encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。