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


PHP toJSON函数代码示例

本文整理汇总了PHP中toJSON函数的典型用法代码示例。如果您正苦于以下问题:PHP toJSON函数的具体用法?PHP toJSON怎么用?PHP toJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: viewStudentProfile

 public static function viewStudentProfile()
 {
     self::requireLogin();
     $studentId = $_SESSION['_id'];
     $profile = toJSON(self::getStudentProfile($studentId));
     self::render('jobs/student/studentprofile', ['profile' => $profile]);
 }
开发者ID:davidliuliuliu,项目名称:sublite,代码行数:7,代码来源:StudentController.php

示例2: toJSON

/**
 * Recursive function to parse nested dictionaries.
 * Un-nests input data and adds hierarchy level to every item.
 *
 * @param  mixed $data  Dictionary which holds menu entries (may contain subitems/-trees)
 * @param  int   $level Hierarchy level of the (sub)tree to start with
 * @return array        An array of JSON objects
 */
function toJSON($data, $level = 0)
{
    $tmp = array();
    $index = 0;
    while ($index < count($data)) {
        $data[$index]['TITLE'] = str_replace("\\", "\\\\", $data[$index]['TITLE']);
        $data[$index]['TITLE'] = str_replace("\"", "\\\"", $data[$index]['TITLE']);
        $entry = '{id:' . $data[$index]['ID'] . ',level:' . $level . ',visible:' . $data[$index]['VISIBLE'] . ',hideChildren:0,text:"' . $data[$index]['TITLE'] . '",link:"' . $data[$index]['URL'] . '"}';
        $tmp[] = $entry;
        if (count($data[$index]['SUBITEMS'])) {
            $tmp = array_merge($tmp, toJSON($data[$index]['SUBITEMS'], $level + 1));
        }
        $index++;
    }
    return $tmp;
}
开发者ID:bcneb,项目名称:WebYep,代码行数:24,代码来源:menu.php

示例3: toJSON

function toJSON($arr)
{
    $json_str = "";
    if (is_array($arr)) {
        $pure_array = true;
        $array_length = count($arr);
        for ($i = 0; $i < $array_length; $i++) {
            if (!isset($arr[$i])) {
                $pure_array = false;
                break;
            }
        }
        if ($pure_array) {
            $json_str = "[";
            $temp = array();
            for ($i = 0; $i < $array_length; $i++) {
                $temp[] = sprintf("%s", toJSON($arr[$i]));
            }
            $json_str .= implode(",", $temp);
            $json_str .= "]";
        } else {
            $json_str = "{";
            $temp = array();
            foreach ($arr as $key => $value) {
                $temp[] = sprintf("\"%s\":%s", $key, toJSON($value));
            }
            $json_str .= implode(",", $temp);
            $json_str .= "}";
        }
    } else {
        if (is_string($arr)) {
            $json_str = "\"" . json_encode_string($arr) . "\"";
        } else {
            if (is_numeric($arr)) {
                $json_str = $arr;
            } else {
                if (is_null($arr)) {
                    $json_str = 'null';
                } else {
                    $json_str = "\"" . json_encode_string($arr) . "\"";
                }
            }
        }
    }
    return $json_str;
}
开发者ID:nelsondaza,项目名称:IDMeasure,代码行数:46,代码来源:TemplateTag.php

示例4: getOut


//.........这里部分代码省略.........
         $this->pageCount[$gname] = $this->getPageCount($table, $this->pageRows[$gname], $req);
         $this->out[$gname] = $this->out[$gname] . ',' . $this->pageCount[$gname] . ',' . $gname;
     } else {
         if (isset($req['pageNumber']) && isset($req['table'])) {
             $gname = trim($req['table']);
             $isCsv = isset($req['command']) && $req['command'] == 'csv';
             $whereClause = $this->whereClause[$gname];
             $werc = isset($req['werc']) ? $req['werc'] : '';
             $werc = str_replace('|', '%', $werc);
             $werc = str_replace('where', ' ', $werc);
             $werc = str_replace("\\'", "'", $werc);
             if ($werc != '' || $whereClause != '') {
                 $werc = ' where ' . $werc . ' ' . ($werc != '' && $whereClause != '' ? 'and ' . $whereClause : $whereClause);
             }
             $ttable = $this->tables[$gname];
             $this->pageCount[$gname] = $this->getPageCount($ttable, $this->pageRows[$gname], $req);
             $this->done = TRUE;
             $gname = trim($req['table']);
             $table = $this->tables[$gname];
             if (isset($req['pageNumber'])) {
                 $this->pageNumber[$gname] = (int) $req['pageNumber'];
             }
             $sort = '';
             $sort_array = array();
             foreach ($req as $rk => $rv) {
                 $sort_tmp = explode("-", $rk);
                 if (count($sort_tmp) == 2 && $sort_tmp[0] == 'sort') {
                     $sort_array[] = $rv;
                 }
             }
             if (count($sort_array) > 0) {
                 $sort = (strpos($werc, 'order') === FALSE ? " order by `" : ',`') . implode('` desc,`', $sort_array) . "` desc";
             }
             if ($this->echoQuery) {
                 echo 'select * from `' . $table . '` ' . $werc . ' ' . $sort . ' limit ' . (int) (($this->pageNumber[$gname] - 1) * $this->pageRows[$gname]) . ',' . (int) $this->pageRows[$gname] . "<br/>\n";
             }
             $mysql->ex_sql('select * from `' . $table . '` ' . $werc . ' ' . $sort . ' limit ' . (int) (($this->pageNumber[$gname] - 1) * $this->pageRows[$gname]) . ',' . (int) $this->pageRows[$gname], $q);
             $i = 0;
             $row = array();
             $csvHead = "";
             $loadHead = TRUE;
             $csvBigBody = "";
             foreach ($q as $rr) {
                 $cell = array();
                 $csvBody = '';
                 foreach ($this->column[$gname] as $k => $field) {
                     $fn = isset($field['cfunction'][0]) ? $field['cfunction'][0] : '';
                     //$tValue = ($fn!='')?$fn(htmlentities($rr[$field['fieldname']])):htmlentities($rr[$field['fieldname']]);
                     $tValue = $fn != '' ? $fn($rr[$field['fieldname']]) : $rr[$field['fieldname']];
                     if ($loadHead) {
                         $csvHead .= ($csvHead != '' ? "," : '') . $field['fieldname'];
                     }
                     //$tmpVal = str_replace("\n",'',((!isset($this->column[$gname][$k]['clist']))?$tValue:$this->column[$gname][$k]['clist'][$rr[$field['fieldname']]]));
                     //$tmpVal = str_replace(',','',$tmpVal);
                     //$tmpVal = mb_convert_encoding($tmpVal,'UTF-8');//,"Windows-1256");
                     //$tmpVal = mb_convert_encoding($tmpVal, 'UTF-16LE', 'UTF-8');
                     //$tmpVal = mb_convert_encoding($tmpVal,"Windows-1252");
                     //if($k > 0)
                     //	$csvBody .= (($csvBody!='')?",":'').strip_tags($tmpVal);
                     $cell[] = array('value' => $tValue, 'css' => $this->loadCellCss($rr['id'], $field['fieldname']), 'typ' => $field['typ']);
                     if (in_array($field['fieldname'], $sort_array)) {
                         $this->column[$gname][$k]['sort'] = 'done';
                     }
                 }
                 $loadHead = FALSE;
                 $csvBigBody .= "{$csvBody}\n";
                 $row[] = array('cell' => $cell, 'css' => $this->loadRowCss($rr['id'], $gname));
             }
             $rowCount = xgrid::getTableRowCount($ttable, $req);
             foreach ($this->column[$gname] as $indx => $column) {
                 if (isset($column['clist'])) {
                     $this->column[$gname][$indx]['clist'] = $this->arrayToObject($column['clist']);
                 }
                 if (isset($column['searchDetails'])) {
                     $this->column[$gname][$indx]['searchDetails'] = $this->arrayToObject($column['searchDetails']);
                 }
             }
             $grid = array('column' => $this->column[$gname], 'rows' => $row, 'cssClass' => $this->css[$gname], 'tableProperty' => $this->tableProperty[$gname], 'css' => '', 'buttonTitles' => $this->buttonTitles[$gname], 'eRequest' => $this->eRequest[$gname], 'pageCount' => $this->pageCount[$gname], 'alert' => $this->alert, 'scrollDown' => $this->scrollDown[$gname], 'xls' => $this->xls[$gname], 'pageRows' => $this->pageRows[$gname], 'rowCount' => $rowCount);
             if (!$isCsv) {
                 $affn = $this->afterCreateFunction[$gname];
                 if ($affn != '') {
                     $fgrid = $affn($grid);
                 } else {
                     $fgrid = $grid;
                 }
                 $this->out[$gname] = toJSON($fgrid);
             } else {
                 $csvOut = "";
                 header('Content-Type: text/csv; charset=utf8');
                 header('Content-disposition: attachment;filename=' . $req['table'] . '.csv');
                 header('Content-type: application/x-msdownload');
                 $this->out[$gname] = $csvBigBody;
                 //.mb_convert_encoding($csvHead."\n".$csvBigBody, 'UTF-16LE', 'UTF-8');
             }
         }
     }
     $gtmp[$gname]['pageCount'] = $this->pageCount[$gname];
     $this->arg = toJSON($gtmp);
     return isset($this->out[$gname]) ? $this->out[$gname] : '';
 }
开发者ID:jnaroogheh,项目名称:darvishi,代码行数:101,代码来源:xgrid.php

示例5: respond

 function respond($err, $resume = null, $fname = null)
 {
     $data = ['error' => $err, 'resume' => $resume, 'fname' => $fname];
     echo toJSON($data);
 }
开发者ID:davidliuliuliu,项目名称:sublite,代码行数:5,代码来源:S3Controller.php

示例6: ps_pay

 public function ps_pay($pardakht_id, $amount)
 {
     $conf = new conf();
     require_once "../class/RSAProcessor.class.php";
     include_once "../simplejson.php";
     $processor = new RSAProcessor("../class/certificate.xml", RSAKeyType::XMLFile);
     $pardakht = new pardakht_class((int) $pardakht_id);
     $merchantCode = $conf->ps_merchantCode;
     $terminalCode = $conf->ps_terminalCode;
     $redirectAddress = $conf->ps_redirectAddress;
     $invoiceNumber = $pardakht_id;
     $timeStamp = str_replace('-', '/', $pardakht->tarikh);
     $invoiceDate = str_replace('-', '/', $pardakht->tarikh);
     $action = "1003";
     // 1003 : براي درخواست خريد
     $data = "#" . $merchantCode . "#" . $terminalCode . "#" . $invoiceNumber . "#" . $invoiceDate . "#" . $amount . "#" . $redirectAddress . "#" . $action . "#" . $timeStamp . "#";
     $data = sha1($data, true);
     $data = $processor->sign($data);
     // امضاي ديجيتال
     $result = base64_encode($data);
     // base64_encode
     $out['invoiceNumber'] = $invoiceNumber;
     $out['invoiceDate'] = $invoiceDate;
     $out['amount'] = $amount;
     $out['terminalCode'] = $terminalCode;
     $out['merchantCode'] = $merchantCode;
     $out['redirectAddress'] = $redirectAddress;
     $out['timeStamp'] = $timeStamp;
     $out['action'] = $action;
     $out['sign'] = $result;
     $outJson = toJSON($out);
     return $outJson;
 }
开发者ID:hscomp2002,项目名称:superp,代码行数:33,代码来源:pay_class.php

示例7: die

<?php

/**
 * Provisioner evolution elements
 *
 * @category  Provisioning
 * @author    S. Hamblett <steve.hamblett@linux.com>
 * @copyright 2010 S. Hamblett
 * @license   GPLv3 http://www.gnu.org/licenses/gpl.html
 * @link      none
 *
 * @package provisioner
 */
/* Protection */
if (REVO_GATEWAY_OPEN != "true") {
    die("Revo Gateway API error - Invalid access");
}
$nodes = array();
/* Grab all the root categories */
$db = connectToDb();
$sql = "SELECT * FROM " . $table_prefix . 'categories';
$result = mysql_query($sql, $db);
while ($category = mysql_fetch_assoc($result)) {
    $class = 'icon-category folder';
    $nodes[] = array('text' => $category['category'] . ' (' . $category['id'] . ')', 'id' => 'n_category_' . $category['id'], 'pk' => $category['id'], 'data' => $category, 'category' => $category['id'], 'leaf' => true, 'cls' => $class, 'page' => '', 'classKey' => 'modCategory', 'type' => 'category');
}
mysql_close($db);
echo toJSON($nodes);
开发者ID:DarWiM,项目名称:provisoner,代码行数:28,代码来源:getnodes.category.php

示例8: json_encode2

 function json_encode2($value)
 {
     if ($value === null) {
         return 'null';
     }
     // gettype fails on null?
     $out = '';
     $esc = "\"\\/\n\r\t" . chr(8) . chr(12);
     // escaped chars
     $l = '.';
     // decimal point
     switch (gettype($value)) {
         case 'boolean':
             $out .= $value ? 'true' : 'false';
             break;
         case 'float':
         case 'double':
             // PHP uses the decimal point of the current locale but JSON expects %x2E
             $l = localeconv();
             $l = $l['decimal_point'];
             // fallthrough...
         // fallthrough...
         case 'integer':
             $out .= str_replace($l, '.', $value);
             // what, no getlocale?
             break;
         case 'array':
             // if array only has numeric keys, and is sequential... ?
             for ($i = 0; $i < count($value) && isset($value[$i]); $i++) {
             }
             if ($i === count($value)) {
                 // it's a "true" array... or close enough
                 $out .= '[' . implode(',', array_map('toJSON', $value)) . ']';
                 break;
             }
             // fallthrough to object for associative arrays...
         // fallthrough to object for associative arrays...
         case 'object':
             $arr = is_object($value) ? get_object_vars($value) : $value;
             $b = array();
             foreach ($arr as $k => $v) {
                 $b[] = '"' . addcslashes($k, $esc) . '":' . toJSON($v);
             }
             $out .= '{' . implode(',', $b) . '}';
             break;
         default:
             // anything else is treated as a string
             return '"' . addcslashes($value, $esc) . '"';
             break;
     }
     return $out;
 }
开发者ID:Lovinity,项目名称:EQM,代码行数:52,代码来源:core.class.php

示例9: session_class

<?php

include_once "../kernel.php";
$SESSION = new session_class();
register_shutdown_function('session_write_close');
session_start();
if (!isset($_SESSION[$conf->app . '_user_id'])) {
    die('error');
}
$se = security_class::auth((int) $_SESSION[$conf->app . '_user_id']);
if (!$se->can_view) {
    die('error');
}
include_once "../simplejson.php";
echo toJSON(session_class::onlineSessions());
开发者ID:hscomp2002,项目名称:superp,代码行数:15,代码来源:online.php

示例10: toJSON

<?
	echo toJSON( $data );
开发者ID:nelsondaza,项目名称:IDMeasure,代码行数:2,代码来源:json.php

示例11: date

     $p_i++;
 }
 for ($k = 0; $k < count($tmp_id); $k++) {
 }
 if ($kharid_typ == 'naghdi') {
     $bool = TRUE;
     $tarikh_now = date("Y-m-d H:i:s");
     /*
     			for($k=0;$k<count($tmp_id);$k++)
     				if(!ticket_class::updateTmp($tmp_id[$k],$info_ticket))
     					$bool = FALSE;
     * 
     */
     if ($bool) {
         $mysql = new mysql_class();
         $pardakht_id = pardakht_class::add(implode(',', $tmp_id), $tarikh_now, $jam_ghimat1, toJSON(array('ticket' => $info_ticket, 'parvaz' => $log_text_info, 'netlog' => $netlog, 'rwaitlog' => $rwaitlog)));
         $pardakht = new pardakht_class($pardakht_id);
         $rahgiri = $pardakht->getBarcode();
         if ($conf->ps === TRUE) {
             $pay_code = pay_class::ps_pay($pardakht_id, $jam_ghimat1);
         } else {
             if ($conf->payline === TRUE) {
                 $pay_code = pay_class::pl_pay($pardakht_id, $jam_ghimat1);
                 $mysql->ex_sqlx("update `pardakht` set `bank_out` = '{$pay_code}' where `id` = {$pardakht_id}");
             } else {
                 $pay_code = pay_class::pay($pardakht_id, $jam_ghimat1);
             }
         }
         //var_dump($pay_code);
         $tmpo = explode(',', $pay_code);
         if (count($tmpo) == 2 && $tmpo[0] == 0 && $conf->ps !== 'TRUE') {
开发者ID:hscomp2002,项目名称:superp,代码行数:31,代码来源:checkflight2.php

示例12: toJSON

function toJSON($data)
{
    require_once 'include/utils.php';
    $json = getJSONobj();
    return $json->encode($data);
}
function findEntity()
{
    $document = new Document();
    // Dokument wiederfinden -> Todo: anhand der field_defs generisch suchen
    $result = $document->get_list('', 'document_name = "' . $_REQUEST['document_name'] . '"');
    return $result['list'][0];
}
function getRevisionBean()
{
    $document = new Document();
    // Dokument wiederfinden -> Todo: anhand der field_defs generisch suchen
    if ($_REQUEST['return_id'] != "" && $_REQUEST['return_id'] != "undefined") {
        $document_id = $_REQUEST['return_id'];
        if ($document->retrieve($document_id)) {
            return $document;
        }
    } else {
        die('Could not get document id!');
    }
}
header("Content-type: application/json");
echo toJSON(create_array(getRevisionBean()));
session_write_close();
?>
 
开发者ID:santara12,项目名称:OpenQuotesAndContracts,代码行数:30,代码来源:GetLatestRevision.php

示例13: mysql_query

    $sql = "SELECT fullname, email, blocked FROM " . $table_prefix . "user_attributes" . " WHERE `internalKey` = " . $manager_user['id'];
    $result = mysql_query($sql, $db);
    while ($manageruser = mysql_fetch_assoc($result)) {
        $manageruser['username'] = $manager_user['username'];
        $manageruser['id'] = $manager_user['id'];
        if ($manageruser['blocked'] == 1) {
            $manageruser['true'];
        } else {
            $manageruser['blocked'] = false;
        }
        $users[] = $manageruser;
    }
}
foreach ($web_users as $web_user) {
    $sql = "SELECT fullname, email, blocked FROM " . $table_prefix . "web_user_attributes" . " WHERE `internalKey` = " . $web_user['id'];
    $result = mysql_query($sql, $db);
    while ($webuser = mysql_fetch_assoc($result)) {
        $webuser['username'] = $web_user['username'];
        $webuser['id'] = $web_user['id'] . '_w';
        if ($webuser['blocked'] == 1) {
            $webuser['true'];
        } else {
            $webuser['blocked'] = false;
        }
        $users[] = $webuser;
    }
}
mysql_close($db);
$count = count($users);
$response = '({"total":"' . $count . '","results":' . toJSON($users) . '})';
echo $response;
开发者ID:DarWiM,项目名称:provisoner,代码行数:31,代码来源:getlist.php

示例14: array

        $class .= ' unpublished';
    }
    if ($item['deleted'] == 1) {
        $class .= ' deleted';
    } else {
        $class .= ' ';
    }
    if ($item['hidemenu'] == 1) {
        $class .= ' hidemenu';
    } else {
        $class .= ' ';
    }
    $qtip = '';
    if ($item['longtitle'] != '') {
        $qtip = '<b>' . $item['longtitle'] . '</b><br />';
    }
    if ($item['description'] != '') {
        $qtip = '<i>' . $item['description'] . '</i>';
    }
    $itemArray = array('text' => $item['pagetitle'] . ' (' . $item['id'] . ')', 'id' => 'evolution' . '_' . $item['id'], 'pk' => $item['id'], 'cls' => $class, 'type' => 'modResource', 'classKey' => 'modDocument', 'key' => $item['id'], 'ctx' => 'evolution', 'qtip' => $qtip, 'preview_url' => '', 'page' => '', 'allowDrop' => true);
    if ($hasChildren) {
        $itemArray['hasChildren'] = true;
        $itemArray['children'] = array();
        $itemArray['expanded'] = true;
    }
    $items[] = $itemArray;
    unset($qtip, $class, $itemArray, $hasChildren);
}
mysql_close($db);
echo toJSON($items);
开发者ID:DarWiM,项目名称:provisoner,代码行数:30,代码来源:getnodes.php

示例15: toJSON

  <question qid="{_id}" class="vanilla" vanilla="{vanilla}" style="{style}">
    <op class="{optype}"></op>
    <text>{text}</text>
  </question>
</questiontemplate>

<vanillaquestionsdata class="hide">
  <?php 
$vanillaQuestions = View::get('vanillaQuestions');
echo toJSON($vanillaQuestions);
?>
</vanillaquestionsdata>
<chosenquestionsdata class="hide">
  <?php 
$chosen = View::get('chosen');
echo toJSON($chosen);
?>
</chosenquestionsdata>

<script>
  function getQuestionFromTemplate(_id, text, elemClass, hide) {
    var style = '';
    if (hide) {
      style = 'display: none;';
    }
    var html = useTemplate('questiontemplate', {
      text: text,
      _id: _id,
      class: elemClass,
      style: style,
      optype: 'plus',
开发者ID:davidliuliuliu,项目名称:sublite,代码行数:31,代码来源:edit.php


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