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


PHP my_json_encode函数代码示例

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


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


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