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

PHP json类代码示例

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

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



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

示例1: _send_reset

 private function _send_reset($form)
 {
     $user_name = $form->reset->inputs["name"]->value;
     $user = user::lookup_by_name($user_name);
     if ($user && !empty($user->email)) {
         $user->hash = random::hash();
         $user->save();
         $message = new View("reset_password.html");
         $message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}");
         $message->user = $user;
         Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=UTF-8")->message($message->render())->send();
         log::success("user", t("Password reset email sent for user %name", array("name" => $user->name)));
     } else {
         if (!$user) {
             // Don't include the username here until you're sure that it's XSS safe
             log::warning("user", t("Password reset email requested for user %user_name, which does not exist.", array("user_name" => $user_name)));
         } else {
             log::warning("user", t("Password reset failed for %user_name (has no email address on record).", array("user_name" => $user->name)));
         }
     }
     // Always pretend that an email has been sent to avoid leaking
     // information on what user names are actually real.
     message::success(t("Password reset email sent"));
     json::reply(array("result" => "success"));
 }
开发者ID:HarriLu,项目名称:gallery3,代码行数:25,代码来源:password.php


示例2: reset_api_key

 public function reset_api_key()
 {
     access::verify_csrf();
     rest::reset_access_key();
     message::success(t("Your REST API key has been reset."));
     json::reply(array("result" => "success"));
 }
开发者ID:kandsten,项目名称:gallery3,代码行数:7,代码来源:rest.php


示例3: make_call

 public function make_call($path, $data = array(), $method = "GET")
 {
     $fields = $this->getFields($data);
     $field_string = implode('&', $fields);
     //open connection
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //what type of request?
     if ($method == "GET") {
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path . '?' . $field_string);
     } elseif ($method == "POST" || $method == "PATCH" || $method == "DELETE") {
         if ($method == "PATCH") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
         }
         if ($method == "DELETE") {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
         }
         curl_setopt($ch, CURLOPT_URL, $this->api_url . $path);
         curl_setopt($ch, CURLOPT_POST, count($fields));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
     }
     //execute post
     $result = curl_exec($ch);
     //close connection
     curl_close($ch);
     //send our data back
     return json::decode($result);
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:28,代码来源:thingiverseapi.php


示例4: confirm

 public function confirm()
 {
     access::verify_csrf();
     $messages = array("error" => array(), "warn" => array());
     $desired_list = array();
     foreach (module::available() as $module_name => $info) {
         if ($info->locked) {
             continue;
         }
         if ($desired = Input::instance()->post($module_name) == 1) {
             $desired_list[] = $module_name;
         }
         if ($info->active && !$desired && module::is_active($module_name)) {
             $messages = array_merge($messages, module::can_deactivate($module_name));
         } else {
             if (!$info->active && $desired && !module::is_active($module_name)) {
                 $messages = array_merge($messages, module::can_activate($module_name));
             }
         }
     }
     if (empty($messages["error"]) && empty($messages["warn"])) {
         $this->_do_save();
         $result["reload"] = 1;
     } else {
         $v = new View("admin_modules_confirm.html");
         $v->messages = $messages;
         $v->modules = $desired_list;
         $result["dialog"] = (string) $v;
         $result["allow_continue"] = empty($messages["error"]);
     }
     json::reply($result);
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:32,代码来源:admin_modules.php


示例5: encodeData

 function encodeData()
 {
     $this->data = $this->pretty_output ? json::pretty($this->data) . "\n" : json_encode($this->data);
     if ($this->data === null) {
         $this->throwJSONError(false, 'Failed to encode $data (' . gettype($this->data) . ') as JSON');
     }
 }
开发者ID:rsms,项目名称:gitblog,代码行数:7,代码来源:JSONStore.php


示例6: get_member_list

 private function get_member_list()
 {
     // Call site settings for stored roster & member ranks to track
     $siteSettings = site::setting();
     // Decode JSON from stored roster data
     $roster = json_decode($siteSettings[0]['fullRoster'], true);
     $data = array();
     // Decode JSON from stored roster ranks
     $ranks = json_decode($siteSettings[0]['rosterRanks'], true);
     $filterRanks = array();
     // Ranks to track
     foreach ($ranks as $key => $value) {
         try {
             // echo $key . ' == ' . $value['track'] . '<br/>';
             if ($value['track']) {
                 $filterRanks[] = $key;
             }
         } catch (Exception $e) {
             //
         }
     }
     foreach ($roster['members'] as $key => $character) {
         // echo var_dump($character['character']);
         // echo $character['character']['name'];
         if (in_array($character['rank'], $filterRanks)) {
             $data[] = $character['character']['name'];
         }
     }
     json::resp(array('success' => true, 'data' => $data));
 }
开发者ID:TheDoxMedia,项目名称:pgs,代码行数:30,代码来源:attendance.worker.php


示例7: request

 function request($type, $url, $get = [], $post = [])
 {
     $developer = cookie::developer();
     if ($developer) {
         $get['_mode'] = 'developer';
     }
     $request = ['method' => $type, 'protocol_version' => '1.1', 'header' => 'Connection: Close'];
     foreach ($post as $name => &$param) {
         if (is_array($param) and empty($param)) {
             $param = '_empty_array';
         }
     }
     if (!empty($post)) {
         $request['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
         $request['content'] = http_build_query($post);
     }
     $ctx = stream_context_create(['http' => $request]);
     $response = file_get_contents($this->endpoint . (empty($get) ? $url : $url . '?' . http_build_query($get)), false, $ctx);
     $object = json::decode($response, true);
     if (is_null($object)) {
         if ($developer) {
             var_dump($response);
             die;
         } else {
             throw new Exception("Error Processing Request", 1);
         }
     }
     $content = $object['content'];
     return (is_object($content) or is_array($content) and array_values($content) !== $content) ? (object) $content : $content;
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:30,代码来源:api.php


示例8: auth

 public function auth()
 {
     if (!identity::active_user()->admin) {
         access::forbidden();
     }
     access::verify_csrf();
     $form = self::_form();
     $valid = $form->validate();
     $user = identity::active_user();
     if ($valid) {
         module::event("user_auth", $user);
         if (!request::is_ajax()) {
             message::success(t("Successfully re-authenticated!"));
         }
         url::redirect(Session::instance()->get_once("continue_url"));
     } else {
         $name = $user->name;
         log::warning("user", t("Failed re-authentication for %name", array("name" => $name)));
         module::event("user_auth_failed", $name);
         if (request::is_ajax()) {
             $v = new View("reauthenticate.html");
             $v->form = $form;
             $v->user_name = identity::active_user()->name;
             json::reply(array("html" => (string) $v));
         } else {
             self::_show_form($form);
         }
     }
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:29,代码来源:reauthenticate.php


示例9: save

 public function save($module_name, $var_name)
 {
     access::verify_csrf();
     module::set_var($module_name, $var_name, Input::instance()->post("value"));
     message::success(t("Saved value for %var (%module_name)", array("var" => $var_name, "module_name" => $module_name)));
     json::reply(array("result" => "success"));
 }
开发者ID:kandsten,项目名称:gallery3,代码行数:7,代码来源:admin_advanced_settings.php


示例10: throwJson

/**
* 抛出json回执信息
* 
* @access public
* @param string $message 消息体
* @param string $charset 信息编码
* @return void
*/
function throwJson($message, $charset = NULL)
{
    /** 设置http头信息 */
    header('content-Type: application/json; charset=' . (empty($charset) ? 'UTF-8' : $charset), true);
    echo json::encode($message);
    /** 终止后续输出 */
    exit;
}
开发者ID:Ethan0814,项目名称:STBlog,代码行数:16,代码来源:json_helper.php


示例11: rsp_err

function rsp_err($msg = '', $status = '400 Bad Request', $bt = null)
{
    $rsp = array('message' => $msg);
    if ($bt) {
        $rsp['bt'] = $bt;
    }
    rsp_ok(json::pretty(array('error' => $rsp)), $status);
}
开发者ID:rsms,项目名称:gitblog,代码行数:8,代码来源:data.php


示例12: add

 public static function add($file, $content)
 {
     $a = json::open($file);
     if (is_array($a)) {
         $a[] = $content;
         return json::save($file, $a);
     }
     return false;
 }
开发者ID:silversthem,项目名称:simPHPle,代码行数:9,代码来源:json.class.php


示例13: show

 /**
  * Allows the given item to be displayed again.
  *
  * @param int $id  the item id
  */
 public function show($id)
 {
     $item = model_cache::get("item", $id);
     $msg = t("Displayed <b>%title</b> item", array("title" => html::purify($item->title)));
     $this->_check_hide_permissions($item);
     hide::show($item);
     message::success($msg);
     json::reply(array("result" => "success", "reload" => 1));
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:14,代码来源:display.php


示例14: inicial

 /**
  * Método inicial do controle
  */
 function inicial()
 {
     $this->entidade = $_GET;
     $arNome = explode(' ', strtolower($this->entidade['entidade']));
     $nome = array_shift($arNome);
     $arNome = array_map("ucFirst", $arNome);
     array_unshift($arNome, $nome);
     $this->nomeEntidade = implode('', $arNome);
     $this->nomeNegocio = "N{$this->nomeEntidade}";
     $xml = array();
     if (arquivo::legivel("{$this->nomeEntidade}/xml/entidade.xml")) {
         $xml['entidade'] = simplexml_load_file("{$this->nomeEntidade}/xml/entidade.xml");
     }
     if (arquivo::legivel("{$this->nomeEntidade}/xml/pt_BR.xml")) {
         $xml['inter'] = simplexml_load_file("{$this->nomeEntidade}/xml/pt_BR.xml");
     }
     $j = new json();
     echo $j->pegarJson($xml);
 }
开发者ID:rafasilvatorres,项目名称:igeorastreador,代码行数:22,代码来源:CUtilitario_pegarDefinicaoEntidade.php


示例15: star_only_off

 public function star_only_off()
 {
     //$item = model_cache::get("item", $id);
     access::verify_csrf();
     $msg = t("Showing all items.");
     //$this->_check_star_permissions($item);
     star::star_only_off();
     message::success($msg);
     json::reply(array("result" => "success", "reload" => 1));
 }
开发者ID:Retroguy,项目名称:gallery3-contrib,代码行数:10,代码来源:display.php


示例16: save

 public function save()
 {
     access::verify_csrf();
     if (!identity::active_user()->admin) {
         access::forbidden();
     }
     $locale = Gallery_I18n::instance()->locale();
     $input = Input::instance();
     $key = $input->post("l10n-message-key");
     $root_message = ORM::factory("incoming_translation")->where("key", "=", $key)->where("locale", "=", "root")->find();
     if (!$root_message->loaded()) {
         throw new Exception("@todo bad request data / illegal state");
     }
     $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message));
     $is_empty = true;
     if ($is_plural) {
         $plural_forms = l10n_client::plural_forms($locale);
         $translation = array();
         foreach ($plural_forms as $plural_form) {
             $value = $input->post("l10n-edit-plural-translation-{$plural_form}");
             if (null === $value || !is_string($value)) {
                 throw new Exception("@todo bad request data");
             }
             $translation[$plural_form] = $value;
             $is_empty = $is_empty && empty($value);
         }
     } else {
         $translation = $input->post("l10n-edit-translation");
         $is_empty = empty($translation);
         if (null === $translation || !is_string($translation)) {
             throw new Exception("@todo bad request data");
         }
     }
     $entry = ORM::factory("outgoing_translation")->where("key", "=", $key)->where("locale", "=", $locale)->find();
     if ($is_empty) {
         if ($entry->loaded()) {
             $entry->delete();
         }
     } else {
         if (!$entry->loaded()) {
             $entry->key = $key;
             $entry->locale = $locale;
             $entry->message = $root_message->message;
             $entry->base_revision = null;
         }
         $entry->translation = serialize($translation);
         $entry_from_incoming = ORM::factory("incoming_translation")->where("key", "=", $key)->where("locale", "=", $locale)->find();
         if (!$entry_from_incoming->loaded()) {
             $entry->base_revision = $entry_from_incoming->revision;
         }
         $entry->save();
     }
     Gallery_I18n::clear_cache($locale);
     json::reply(new stdClass());
 }
开发者ID:HarriLu,项目名称:gallery3,代码行数:55,代码来源:l10n_client.php


示例17: auth_ajax

 public function auth_ajax()
 {
     access::verify_csrf();
     list($valid, $form) = $this->_auth("login/auth_ajax");
     if ($valid) {
         json::reply(array("result" => "success"));
     } else {
         $view = new View("login_ajax.html");
         $view->form = $form;
         json::reply(array("result" => "error", "html" => (string) $view));
     }
 }
开发者ID:HarriLu,项目名称:gallery3,代码行数:12,代码来源:login.php


示例18: doClear

 public function doClear($id)
 {
     $photo = ORM::factory("item", $id);
     $rateid = "rate" . $id;
     $ratable = db::build()->select("id")->from("ratables")->where("ratableKey", "=", $rateid)->execute()->current();
     if (db::build()->select("id")->from("ratings")->where("ratable_id", "=", $ratable->id)->execute()->count() < 1) {
         message::warning(t("No votes have been registered for this item:  Nothing cleared!"));
         json::reply(array("result" => "success", "location" => $photo->url()));
         return;
     }
     $ratings = db::build()->delete("ratings")->where("ratable_id", "=", $ratable->id)->execute();
     message::success(t("All ratings and votes for this item have been cleared!"));
     json::reply(array("result" => "success", "location" => $photo->url()));
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:14,代码来源:ratings.php


示例19: __construct

 public function __construct($status, $username, $data)
 {
     $json = new json();
     $json->add('Status', $status);
     $json->add('Username', $username);
     $json->add('UserData', $data);
     $json->add('Success');
     $this->json = $json->make();
 }
开发者ID:shpocher,项目名称:Simple-Json-PHP,代码行数:9,代码来源:custom.php


示例20: _reauth_check

 private static function _reauth_check()
 {
     $session = Session::instance();
     $last_active_auth = $session->get("active_auth_timestamp", 0);
     $last_admin_area_activity = $session->get("admin_area_activity_timestamp", 0);
     $admin_area_timeout = module::get_var("gallery", "admin_area_timeout");
     $time_remaining = max($last_active_auth, $last_admin_area_activity) + $admin_area_timeout - time();
     $result = new stdClass();
     $result->result = "success";
     if ($time_remaining < 30) {
         message::success(t("Automatically logged out of the admin area for your security"));
         $result->location = url::abs_site("");
     }
     json::reply($result);
 }
开发者ID:kandsten,项目名称:gallery3,代码行数:15,代码来源:admin.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP jsonRPCClient类代码示例发布时间:2022-05-23
下一篇:
PHP js_writer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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