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


PHP json类代码示例

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


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


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