• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP my_json_encode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_auto_marking_sc

function test_auto_marking_sc($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale'], '/new-question/errors');
    try {
        $model = new Model();
        $raw_input = $request->getBody();
        $content_type = explode(';', $request->type)[0];
        if ($content_type !== 'application/json') {
            Util::output_errors_and_die($msg->_('invalid-format'), 415);
        }
        $input_data = json_decode($raw_input, true);
        if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['source-code']) || !is_string($input_data['source-code'])) {
            Util::output_errors_and_die($msg->_('invalid-format'), 400);
        }
        $extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
        $qd = $input_data['question'];
        set_empty_if_undefined($qd['type']);
        if ($qd['type'] != 'source-code') {
            Util::output_errors_and_die('', 400);
        }
        $q = new QuestionSC($qd, Question::FROM_USER, $extra);
        $q->mark_automatically(array('source-code' => $input_data['source-code']), $log, $result);
        http_response_code(200);
        header('Content-Type: application/json');
        echo my_json_encode($result);
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:32,代码来源:test_auto_marking_sc.php


示例2: test_auto_marking

function test_auto_marking($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale'], '/new-question/errors');
    try {
        $model = new Model();
        $raw_input = $request->getBody();
        $content_type = explode(';', $request->type)[0];
        if ($content_type !== 'application/json') {
            Util::output_errors_and_die($msg->_('invalid-format'), 415);
        }
        $input_data = json_decode($raw_input, true);
        if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['studentAnswer'])) {
            Util::output_errors_and_die($msg->_('invalid-format'), 400);
        }
        $extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
        $qd = $input_data['question'];
        set_empty_if_undefined($qd['type']);
        if (!Validator::validate_question_type($qd['type'])) {
            Util::output_errors_and_die($msg->_('invalid-type'), 400);
        }
        switch ($qd['type']) {
            case 'short-answer':
                $q = new QuestionSA($qd, Question::FROM_USER, $extra);
                break;
            case 'essay':
                $q = new QuestionES($qd, Question::FROM_USER, $extra);
                break;
            case 'multiple-choice':
                $q = new QuestionMC($qd, Question::FROM_USER, $extra);
                break;
            case 'matching':
                $q = new QuestionMA($qd, Question::FROM_USER, $extra);
                break;
            case 'fitb-type':
                $q = new QuestionFT($qd, Question::FROM_USER, $extra);
                break;
            case 'fitb-select':
                $q = new QuestionFS($qd, Question::FROM_USER, $extra);
                break;
            case 'source-code':
                $q = new QuestionSC($qd, Question::FROM_USER, $extra);
                break;
        }
        http_response_code(200);
        header('Content-Type: application/json');
        $mark = $q->mark_automatically($input_data['studentAnswer'], $log);
        foreach ($log as $i => $line) {
            $log[$i] = $msg->_('/auto-marking/' . $line[0], $line[1]);
        }
        $log = implode('<br/>', $log);
        echo my_json_encode(array('log' => $log, 'mark' => $mark));
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:58,代码来源:test_auto_marking.php


示例3: create_session

function create_session($request)
{
    $raw_input = $request->getBody();
    $content_type = explode(';', $request->type)[0];
    switch ($content_type) {
        case 'application/json':
            $input_data = json_decode($raw_input, true);
            break;
        case 'application/x-www-form-urlencoded':
            $input_data = array();
            parse_str($raw_input, $input_data);
            break;
        default:
            Util::output_errors_and_die('', 415);
    }
    if ($input_data === null) {
        Util::output_errors_and_die('', 400);
    }
    set_empty_if_undefined($input_data['username_or_email']);
    set_empty_if_undefined($input_data['password']);
    $msg = new Messages($GLOBALS['locale'], '/signin');
    try {
        $model = new Model();
        $user_data = $model->is_valid_user($input_data['username_or_email'], $input_data['password']);
        if (!$user_data) {
            Util::output_errors_and_die($msg->_('invalid-username-pw'), 403);
        }
        switch ($user_data['status']) {
            case 'pending-activation':
                Util::output_errors_and_die($msg->_('pending-activation'), 403);
                break;
            case 'pending-approval':
                Util::output_errors_and_die($msg->_('pending-approval'), 403);
                break;
            case 'banned':
                Util::output_errors_and_die($msg->_('banned'), 403);
                break;
            case 'active':
                $token = generate_token($user_data);
                $now = new DateTime('now');
                $expires_at = clone $now;
                $expires_at->add(new DateInterval('P7D'));
                $model->insert_auth_token($user_data['user_id'], $token, $now, $expires_at);
                http_response_code(201);
                $output = array('token' => $token, 'expires_at' => $expires_at->format('Y-m-d H:i:s'));
                setcookie('authToken', $token, $expires_at->getTimestamp(), '/', '', $secure = true, $httponly = true);
                header('Content-Type: application/json');
                echo my_json_encode($output);
                die;
                break;
        }
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:57,代码来源:create_session.php


示例4: to_sql

 public function to_sql()
 {
     $qd = parent::to_sql();
     $qd['answers'] = my_json_encode(array_map(function ($a) {
         return $a['text'];
     }, $this->answers));
     $qd['hex_ids'] = implode(',', array_keys($this->answers_by_hex_id));
     return $qd;
 }
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:9,代码来源:QuestionFS.class.php


示例5: __construct

 public function __construct($message = null, $code = 0)
 {
     if ($message) {
         $msg = new Messages($GLOBALS['locale']);
         $err = array('DATABASE-ERROR' => $msg->_('/showmsg/database-error'));
         // discard original message
         $message = my_json_encode($err);
     }
     parent::__construct($message, $code);
 }
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:10,代码来源:DatabaseException.class.php


示例6: test_question

function test_question($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale'], '/new-question/errors');
    try {
        $model = new Model();
        $raw_input = $request->getBody();
        $content_type = explode(';', $request->type)[0];
        if ($content_type !== 'application/json') {
            Util::output_errors_and_die($msg->_('invalid-format'), 415);
        }
        $input_data = json_decode($raw_input, true);
        if (empty($input_data)) {
            Util::output_errors_and_die($msg->_('invalid-format'), 400);
        }
        set_empty_if_undefined($input_data['type']);
        if (!Validator::validate_question_type($input_data['type'])) {
            Util::output_errors_and_die($msg->_('invalid-type'), 400);
        }
        switch ($input_data['type']) {
            case 'short-answer':
                $q = new QuestionSA($input_data, Question::FROM_USER);
                break;
            case 'essay':
                $q = new QuestionES($input_data, Question::FROM_USER);
                break;
            case 'multiple-choice':
                $q = new QuestionMC($input_data, Question::FROM_USER);
                break;
            case 'matching':
                $q = new QuestionMA($input_data, Question::FROM_USER);
                break;
            case 'fitb-type':
                $q = new QuestionFT($input_data, Question::FROM_USER);
                break;
            case 'fitb-select':
                $q = new QuestionFS($input_data, Question::FROM_USER);
                break;
            case 'source-code':
                $q = new QuestionSC($input_data, Question::FROM_USER);
                break;
        }
        http_response_code(200);
        header('Content-Type: application/json');
        echo my_json_encode($q->to_auto_marking_test(true, true));
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:51,代码来源:test_question.php


示例7: my_json_encode

function my_json_encode(array $data)
{
    $s = array();
    foreach ($data as $k => $v) {
        if (is_array($v)) {
            $v = my_json_encode($v);
            $s[] = "\"{$k}\":{$v}";
        } else {
            $v = addslashes(str_replace(array("\n", "\r"), '', $v));
            $s[] = "\"{$k}\": \"{$v}\"";
        }
    }
    return '{' . implode(', ', $s) . '}';
}
开发者ID:houbaron,项目名称:Coop,代码行数:14,代码来源:function.php


示例8: getFilesArray

 function getFilesArray($value)
 {
     $filesArray = my_json_decode($value);
     if (!is_array($filesArray) || count($filesArray) == 0) {
         if ($value == "") {
             $filesArray = array();
         } else {
             $uploadedFile = $this->upload_handler->get_file_object($value);
             if (is_null($uploadedFile)) {
                 $filesArray = array();
             } else {
                 $filesArray = array(my_json_decode(my_json_encode($uploadedFile)));
             }
         }
     }
     return $filesArray;
 }
开发者ID:aagusti,项目名称:padl-tng,代码行数:17,代码来源:ViewFileField.php


示例9: get_programming_languages

function get_programming_languages($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale']);
    try {
        $model = new Model();
        $result = $model->get_programming_languages();
        http_response_code(200);
        header('Content-Type: application/json');
        echo my_json_encode($result);
        die;
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:17,代码来源:get_programming_languages.php


示例10: createMenuAction

 public function createMenuAction()
 {
     //获取access_token
     $appid = C("APPID");
     $appsecret = C("APPSECRET");
     $wechatInterface = new wechatInterfaceapiLogic();
     $access_token = $wechatInterface->getAccessToken($appid, $appsecret);
     //将数组重排成树
     $MenuL = new CustomMenuLogic();
     $lists = $MenuL->getLists();
     $tree = list_to_tree($lists, 'id', 'pid', 'sub_button');
     $menus = array();
     $wechatMenu = new wechatMenuapiLogic();
     $wechatMenu->setAccessToken($access_token);
     $wechatMenu->deleteMenu();
     //将树转换成json格式的树
     $array = $wechatMenu->createJson($tree);
     //将数组转化成符合要求的json数据
     $json = my_json_encode('text', $array);
     $wechatMenu->createMenus($json);
 }
开发者ID:HebutJipeng,项目名称:Ethan-Wechat,代码行数:21,代码来源:CustomMenuController.class.php


示例11: test

 public static function test($file_name, $extension, $source_code, $compiler_flags, $check_command, $compile_command, $run_command, $arguments, $stdin)
 {
     $file_name_with_ext = $file_name . '.' . $extension;
     if ($compile_command) {
         $flags_string = '';
         foreach ($compiler_flags as $f) {
             $flags_string .= ' ' . escapeshellarg($f);
         }
         if ($flags_string) {
             $index = mb_strpos($compile_command, ' ');
             if ($index !== false) {
                 $compile_command = substr_replace($compile_command, $flags_string, $index, 0);
             } else {
                 $compile_command .= ' ' . $flags_string;
             }
         }
     }
     $spr = new StudentProgramRunner($file_name_with_ext, $source_code, $check_command, $compile_command, $run_command);
     $stop = false;
     if ($check_command) {
         $r = $spr->check();
         $result['check'] = $r;
         if ($r === null || $r['return_value']) {
             $stop = true;
         }
     }
     if ($compile_command and !$stop) {
         $r = $spr->compile();
         $result['compile'] = $r;
         if ($r === null || $r['return_value']) {
             $stop = true;
         }
     }
     if ($run_command and !$stop) {
         $r = $spr->run($arguments, $stdin);
         $result['run'] = $r;
     }
     $spr = null;
     echo my_json_encode($result);
 }
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:40,代码来源:LanguageTest.class.php


示例12: get_user

function get_user($request, $username)
{
    Authenticator::assert_manager($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale']);
    try {
        $model = new Model();
        $request->query['fields'] = implode(',', ['username', 'email', 'gender', 'full_name', 'birth_date', 'created_at', 'last_logged_in_at', 'status', 'role']);
        $request->query['username'] = $username;
        $result = $model->get_users($request->query);
        if ($result['n_items'] == 0) {
            http_response_code(404);
            die;
        }
        http_response_code(200);
        header('Content-Type: application/json');
        echo my_json_encode($result['items'][0]);
        die;
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:23,代码来源:get_user.php


示例13: delete

 public function delete()
 {
     $fileName = postvalue("fileName");
     $success = false;
     if (isset($_SESSION["mupload_" . $this->formStamp][$fileName])) {
         if (!$_SESSION["mupload_" . $this->formStamp][$fileName]["fromDB"]) {
             $sessionFile = $_SESSION["mupload_" . $this->formStamp][$fileName]["file"];
             $file_path = $sessionFile["name"];
             if (is_file($file_path)) {
                 $success = unlink($file_path);
             }
             if ($success && $sessionFile["thumbnail"] != "") {
                 $file = $sessionFile["thumbnail"];
                 if (is_file($file)) {
                     unlink($file);
                 }
             }
             unset($_SESSION["mupload_" . $this->formStamp][$fileName]);
         } else {
             $_SESSION["mupload_" . $this->formStamp][$fileName]["deleted"] = true;
             $success = true;
         }
     }
     header('Content-type: application/json');
     echo my_json_encode($success);
 }
开发者ID:ryanblanchard,项目名称:Dashboard,代码行数:26,代码来源:uploadhandler.php


示例14: getFieldValueCopy

 /**
  * @param String fieldValue
  * @return String
  */
 function getFieldValueCopy($fieldValue)
 {
     $this->initUploadHandler();
     $uploadFolder = $this->pageObject->pSetEdit->getUploadFolder($this->field);
     $absoluteUploadDirPath = $this->pageObject->pSetEdit->getFinalUploadFolder($this->field);
     $filesData = my_json_decode($fieldValue);
     if (!is_array($filesData) || count($filesData) == 0) {
         return $fieldValue;
     }
     foreach ($filesData as $idx => $fileData) {
         $info = $this->upload_handler->pathinfo_local($fileData["usrName"]);
         $newFieldName = $this->upload_handler->tempnam_sfx($absoluteUploadDirPath, $info['filename'], $info['extension']);
         runner_copy_file(getabspath($fileData["name"]), $absoluteUploadDirPath . $newFieldName);
         $filesData[$idx]["name"] = $uploadFolder . $newFieldName;
         if ($this->pageObject->pSetEdit->getCreateThumbnail($this->field)) {
             $thumbnailPrefix = $this->pageObject->pSetEdit->getStrThumbnail($this->field);
             $newThumbName = $this->upload_handler->tempnam_sfx($absoluteUploadDirPath, $thumbnailPrefix . $info['filename'], $info['extension']);
             runner_copy_file(getabspath($fileData["thumbnail"]), $absoluteUploadDirPath . $newThumbName);
             $filesData[$idx]["thumbnail"] = $uploadFolder . $newThumbName;
         }
     }
     return my_json_encode($filesData);
 }
开发者ID:kcallow,项目名称:MatchMe,代码行数:27,代码来源:FileField.php


示例15: to_sql

 public function to_sql()
 {
     $qd = parent::to_sql();
     $qd['answers'] = my_json_encode($this->raw_answer);
     return $qd;
 }
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:6,代码来源:QuestionES.class.php


示例16: array

    if ($i == 1) {
        $options["masterKeysReq"] = array();
    }
    $options["masterKeysReq"][$i] = $_REQUEST["masterkey" . $i];
    $i++;
}
//	Create $pageObject
$pageObject = ListPage::createListPage($strTableName, $options);
// Read Search parameters from the request
if (postvalue("saveSearch") && postvalue("searchName") && !is_null($pageObject->searchLogger)) {
    $searchName = postvalue("searchName");
    $searchParams = $pageObject->getSearchParamsForSaving();
    $pageObject->searchLogger->saveSearch($searchName, $searchParams);
    $pageObject->searchClauseObj->savedSearchIsRun = true;
    $_SESSION[$pageObject->sessionPrefix . '_advsearch'] = serialize($pageObject->searchClauseObj);
    echo my_json_encode($searchParams);
    exit;
}
// Delete the saved search
if (postvalue("deleteSearch") && postvalue("searchName") && !is_null($pageObject->searchLogger)) {
    $searchName = postvalue("searchName");
    $pageObject->searchLogger->deleteSearch($searchName);
    exit;
}
$gQuery->ReplaceFieldsWithDummies($pageObject->getNotListBlobFieldsIndices());
if ($mode != LIST_DETAILS) {
}
unset($_SESSION["message_add"]);
unset($_SESSION["message_edit"]);
// prepare code for build page
$pageObject->prepareForBuildPage();
开发者ID:ryanblanchard,项目名称:Dashboard,代码行数:31,代码来源:Fact_SalesTransaction_list.php


示例17: db_stripslashesbinary

             $value = db_stripslashesbinary($data[$field]);
         }
     } else {
         $cipherer = new RunnerCipherer($strTableName, $pSet);
         $row = $cipherer->DecryptFetchedArray($rs);
         if (!is_null($row)) {
             $filesArray = my_json_decode($row[$field]);
             if (!is_array($filesArray) || count($filesArray) == 0) {
                 if ($row[$field] == "") {
                     $filesArray = array();
                 } else {
                     $uploadedFile = $upload_handler->get_file_object($row[$field]);
                     if (is_null($uploadedFile)) {
                         $filesArray = array();
                     } else {
                         $filesArray = array(my_json_decode(my_json_encode($uploadedFile)));
                     }
                 }
             }
             foreach ($filesArray as $uploadedFile) {
                 if ($uploadedFile["usrName"] == $fileName) {
                     $sessionFile = $uploadedFile;
                     break;
                 }
             }
         }
     }
 }
 $iconShowed = false;
 if ($isDBFile) {
     $ftype = "";
开发者ID:aagusti,项目名称:padl-tng,代码行数:31,代码来源:mfhandler.php


示例18: my_json_encode

    $pageObject->body['end'] .= "window.settings = " . my_json_encode($pageObject->jsSettings) . ";";
    $pageObject->body['end'] .= '</script>';
    $pageObject->body['end'] .= "<script language=\"JavaScript\" src=\"include/runnerJS/RunnerAll.js\"></script>\r\n";
    $pageObject->body["end"] .= "<script>" . $pageObject->PrepareJs() . "</script>";
    $xt->assignbyref("body", $pageObject->body);
    $xt->display($templatefile);
    exit;
} else {
    if ($mode == SEARCH_LOAD_CONTROL) {
        $searchControlBuilder = new PanelSearchControl($searchControllerId, $strTableName, $pageObject->searchClauseObj, $pageObject);
        $ctrlField = postvalue('ctrlField');
        $ctrlBlockArr = $searchControlBuilder->buildSearchCtrlBlockArr($id, $ctrlField, 0, '', false, true, '', '');
        // build array for encode
        $resArr = array();
        $resArr['control1'] = trim($xt->call_func($ctrlBlockArr['searchcontrol']));
        $resArr['control2'] = trim($xt->call_func($ctrlBlockArr['searchcontrol1']));
        $resArr['comboHtml'] = trim($ctrlBlockArr['searchtype']);
        $resArr['delButt'] = trim($ctrlBlockArr['delCtrlButt']);
        $resArr['delButtId'] = trim($searchControlBuilder->getDelButtonId($ctrlField, $id));
        $resArr['divInd'] = trim($id);
        $resArr['fLabel'] = GetFieldLabel(GoodFieldName($strTableName), GoodFieldName($ctrlField));
        $resArr['ctrlMap'] = $pageObject->controlsMap['controls'];
        if (postvalue('isNeedSettings') == 'true') {
            $pageObject->fillSettings();
            $resArr['settings'] = $pageObject->jsSettings;
        }
        // return JSON
        echo my_json_encode($resArr);
        exit;
    }
}
开发者ID:aagusti,项目名称:padl-tng,代码行数:31,代码来源:public_tmp_bank2_search.php


示例19: SecurityRedirect

function SecurityRedirect($inlineedit)
{
    if ($inlineedit == EDIT_INLINE) {
        echo my_json_encode(array("success" => false, "message" => "The record is not editable"));
        return;
    }
    $_SESSION["MyURL"] = $_SERVER["SCRIPT_NAME"] . "?" . $_SERVER["QUERY_STRING"];
    header("Location: menu.php?message=expired");
}
开发者ID:aagusti,项目名称:padl-tng,代码行数:9,代码来源:app_modules_edit.php


示例20: my_json_encode_unescaped_unicode

function my_json_encode_unescaped_unicode($value)
{
    array_walk_recursive($value, 'json_mb_encode_numericentity');
    return runner_decode_numeric_entity(my_json_encode($value), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
开发者ID:sdev1,项目名称:CloudStockEnquiry,代码行数:5,代码来源:dbcommon.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP my_log函数代码示例发布时间:2022-05-15
下一篇:
PHP my_json_decode函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap