本文整理汇总了PHP中JSON函数的典型用法代码示例。如果您正苦于以下问题:PHP JSON函数的具体用法?PHP JSON怎么用?PHP JSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sign_action
public function sign_action()
{
if (!$this->input->is_ajax_request()) {
show_404();
}
$e = $this->input->post('name', true);
$c = $this->input->post('captcha', true);
$p = $this->input->post('password', true);
$e = strtolower(trim($e));
$p = strtolower(trim($p));
$c = strtolower(trim($c));
$sess = $this->session->userdata('captcha');
if (md5($c) != $sess) {
JSON('error', '验证码输入有误!');
}
/** 登录用户登录状态 */
$user = $this->auth->checkuserlogin($e, $p);
if (false === $user) {
JSON('error', '用户名或密码错误!');
}
$arr = explode('|', config_item('site_admin_uid'));
if (!$user->uid or !in_array($user->uid, $arr)) {
JSON('error', '你的账号状态不正常!');
}
/** 处理用户登录 */
$this->auth->process_login($user);
JSON('success', '登录成功!', admin_site_url());
}
示例2: move_group
function move_group($id, $group_id)
{
is_array($id) || ($id = explode(',', $id));
$data['uid'] = $map['uid'] = array('in', $id);
// $data ['group_id'] = $group_id; //TODO 前端微信用户只能有一个微信组
$res = M('auth_group_access')->where($data)->delete();
$data['group_id'] = $group_id;
foreach ($id as $uid) {
$data['uid'] = $uid;
$res = M('auth_group_access')->add($data);
// 更新用户缓存
D('Common/User')->getUserInfo($uid, true);
}
$group = $this->find($group_id);
// 同步到微信端
if (C('USER_GROUP') && !empty($group['wechat_group_id'])) {
$url = 'https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=' . get_access_token();
$map['token'] = get_token();
$follow = M('public_follow')->where($map)->field('openid, uid')->select();
foreach ($follow as $v) {
if (empty($v['openid'])) {
continue;
}
$param['openid'] = $v['openid'];
$param['to_groupid'] = $group['wechat_group_id'];
$param = JSON($param);
$res = post_data($url, $param);
}
}
return $group;
}
示例3: callback
function callback($status, $msg = 'Yes!', $data = array())
{
$return = array('status' => $status, 'msg' => $msg, 'data' => $data, 'num' => count($data));
header('charset=utf-8');
//die(json_encode($return));
exit(JSON($return));
}
示例4: list_data
function list_data()
{
$page = I('p', 1, 'intval');
$map['token'] = get_token();
$list_data = M('coupon_shop')->where($map)->order('id DESC')->page($page, 20)->selectPage(20);
// dump ( $list_data );
echo JSON($list_data);
}
示例5: infopart_list
public function infopart_list($start, $end)
{
$info_db = M('info');
$map['infoid'] = array(array('gt', $start), array('lt', $end));
$data = $info_db->where($map)->select();
header('Content-Type:text/html;Charset=UTF-8');
echo JSON($data);
}
示例6: callback
/**
* 统一数据返回
* @param unknown_type $status
* @param unknown_type $msg
* @param unknown_type $data
*/
protected function callback($status, $msg = 'Yes!', $data = array())
{
$return = array('status' => $status, 'msg' => $msg, 'data' => $data, 'num' => count($data));
// header('Content-Type:text/html;charset=utf-8');
header('Content-Type:application/json;charset=utf-8');
//die(json_encode($return));
die(JSON($return));
}
示例7: post_youkang_data1
function post_youkang_data1($url, $param, $is_file = false, $return_array = true)
{
$param = JSON($param);
$data = http_build_query($param);
$length = strlen($data);
$fp = fsockopen("http://www.youkang120.com", 80, $errno, $errstr, 10) or exit($errstr . "--->" . $errno);
$header = "POST /mobileConsultationList HTTP/1.1\r\n";
$header .= "Host:localhost\r\n";
$header .= "Content-Length: " . $lenght . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= 'Connection: Keep-Alive\\r\\n';
$header .= 'Pragma: no-cache\\r\\n';
$header .= 'Cache-Control: no-cache\\r\\n';
$header .= "Connection: Close\r\n\r\n";
$header .= $data . "\r\n";
fwrite($fp, $header);
while (!feof($fp)) {
echo fgets($fp, 1280);
}
fclose($fp);
}
示例8: stats_action
public function stats_action()
{
if (!$this->input->is_ajax_request()) {
show_404();
}
$this->_clear();
$stats = $this->_stats();
JSON('success', '共计 ' . $stats['rows'] . ' 个标签,当前操作已成功更新 ' . $stats['affe'] . ' 条记录!');
}
示例9: post_data
function post_data($url, $param, $is_file = false, $return_array = true)
{
if (!$is_file && is_array($param)) {
$param = JSON($param);
}
if ($is_file) {
$header[] = "content-type: multipart/form-data; charset=UTF-8";
} else {
$header[] = "content-type: application/json; charset=UTF-8";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
$flat = curl_errno($ch);
if ($flat) {
$data = curl_error($ch);
addWeixinLog($flat, 'post_data flat');
addWeixinLog($data, 'post_data msg');
}
curl_close($ch);
$return_array && ($res = json_decode($res, true));
return $res;
}
示例10: baidu
$search_text = $_POST['search_text'];
$sql = "insert into baidu(search_text) values(" . "'{$search_text}'" . ")";
mysql_query($sql, $conn);
echo "save_ok";
mysql_close($conn);
}
} else {
if ($code == "show") {
if ($_POST['search_text']) {
$search_text = $_POST['search_text'];
//使用模糊查询进行关键字搜索
$sql = "select search_text from baidu where search_text like '%" . $search_text . "%'";
$res = mysql_query($sql, $conn);
$result = "";
while ($row = mysql_fetch_assoc($res)) {
$result = $result . JSON($row) . "#";
//以#字符作为json字符串数组的分隔符
}
echo $result;
mysql_free_result($res);
mysql_close($conn);
}
} else {
if ($code == "delete") {
if ($_POST['search_text']) {
$search_text = $_POST['search_text'];
//删除该关键字的数据库记录
$sql = "delete from baidu where search_text = '{$search_text}'";
$res = mysql_query($sql, $conn);
if ($res) {
$result = "succeed";
示例11: verificarLogin
function verificarLogin()
{
$datos = $_POST;
try {
$user = Usuario_NetoSolis::find(array('conditions' => array('email = ? AND password = ?', $datos['email'], $datos['password'])));
if ($user) {
if ($user->status == 1) {
JSON(true, 'Bienvenido tus datos son correctos.');
} else {
JSON(false, 'Tu cuenta no esta activada. Te enviamos un email con un link para activar tu cuenta.');
}
} else {
JSON(false, 'Los datos son incorrectos. Favor de verificarlos.');
}
} catch (Exception $e) {
JSON(false, 'Los datos son incorrectos. Favor de verificarlos.' . $e);
}
}
示例12: while
<?php
require "link.php";
require "jsonHelper.php";
$array;
$i = 0;
$sql = "SELECT * FROM weekassignment WHERE id >0";
$result = $mysql->query($sql);
while ($final = $result->fetch_array()) {
$array[$i]['id'] = $final['id'];
$array[$i]['startdate'] = $final['startdate'];
$array[$i]['enddate'] = $final['enddate'];
$array[$i]['assignment'] = $final['assignment'];
$array[$i]['process'] = $final['process'];
$i++;
}
echo JSON($array);
示例13: _send_by_openid
function _send_by_openid($openids)
{
$openids = wp_explode($openids);
if (empty($openids)) {
$this->error('要发送的OpenID值不能为空');
}
if (count($openids) < 2) {
$this->error('OpenID至少需要2个或者2个以上');
}
$url = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=' . get_access_token();
$info = $this->_sucai_media_info();
$param['touser'] = $openids;
if ($info['msgtype'] == 'text') {
$param['text']['content'] = $info['media_id'];
$param['msgtype'] = $info['msgtype'];
} else {
if ($info['msgtype'] == 'mpnews') {
$param['mpnews']['media_id'] = $info['media_id'];
$param['msgtype'] = $info['msgtype'];
} else {
if ($info['msgtype'] == 'voice') {
$param['voice']['media_id'] = $info['media_id'];
$param['msgtype'] = $info['msgtype'];
} else {
if ($info['msgtype'] == 'mpvideo') {
$param['video']['media_id'] = $info['media_id'];
$param['msgtype'] = $info['video'];
}
}
}
}
$param = JSON($param);
$res = post_data($url, $param);
if ($res['errcode'] != 0) {
$this->error(error_msg($res));
} else {
return $res['msg_id'];
}
}
示例14: delete_action
public function delete_action()
{
if (!$this->input->is_ajax_request()) {
show_404();
}
$cid = (int) $this->input->post('cid');
$new = (int) $this->input->post('newcategory');
$category = $this->category_model->get_info(array('cid' => $cid));
if (!$category or $new === 0) {
JSON('error', '对不起,没有找到您要删除的分类!');
}
$this->db->delete('category', array('cid' => $cid));
if ($this->db->affected_rows()) {
// 转移该分类下的所有文章
$this->db->update('article', array('cid' => $new), array('cid' => $cid));
JSON('success', '恭喜,分类 ' . $category->name . ' 删除成功!');
} else {
JSON('error', '对不起,删除分类失败,请重试!');
}
}
示例15: array
case 'getpersons':
if ($type == 0) {
$persons = PersonManager::searchPersons($query, 1, -1);
} else {
$persons = PersonManager::searchPersonsBySunccoNo($query, 1, -1);
}
if ($persons === false) {
return;
}
$personNames = array();
$personCount = count($persons['persons']);
for ($i = 0; $i < $personCount; $i++) {
$person = $persons['persons'][$i];
$personNames[$i] = $person->name . "_" . $person->personId . "_" . $person->sunccoNo;
}
echo JSON($personNames);
return;
break;
case 'getBorrowerInfo':
if (strlen($query) != 0) {
$person = BookManager::getPerson($query);
if ($person === false) {
echo "";
} else {
echo $person->name . "_" . $person->personId . "_" . $person->sunccoNo;
}
}
break;
default:
break;
}