Maison >développement back-end >tutoriel php >php形成json语句,多出前面一句,怎么去掉!
php源码
<?php //session start session_start(); include "./mobile/sql.php"; $con = mysql_connect($domain,$usrnm,$password); mysql_select_db($usrnm) or die('Could not select database'); mysql_query("set character set 'utf8'"); $page = $_GET['page']; if(!$con){ echo("can not connect"); } else{ //1.登陆授权 if($page=='login'){ //1.读取用户数据,并进行匹配 $usrname = $_GET['usrnm']; $pas = $_GET['pas']; //2.检索数据库 $sql = "select * from mb_usr"; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); while( $row = mysql_fetch_array($result) ){ if(($row['usrid']==$usrname || $row['mail']==$usrname || $row['phoneno']==$usrname) && $row['pas']==$pas){ //3.分配session值 保留登陆时限 $_SESSION[$usrname] = $usrname; //4.构建login的json格式 $jsonArr = Array('logintype'=>$row['usrtype'],'sessionid'=>$usrname,'usrnm'=>$row['usrnm'],'usrid'=>$row['usrid']); echo json_encode($jsonArr); break; } else{ echo '{"logintype":"-1"}'; } } } }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">{"logintype":"0","sessionid":"0","usrnm":"mjc","usrid":"0"}
把相关程序文件转存为无bom的utf8文件就OK了。
方法最好用新建无bom文件,把代码复制过去,再保存。
php页面里去掉这句不就行了
json输出前加入
header('Content-type: application/json');
试试~
php页面里去掉这句不就行了
include "./mobile/sql.php"; 这个里的吧
估计是 include "./mobile/sql.php"; 文件生成的吧,贴出来看看。
从来没有遇到过这样的奇葩问题了,呵呵
header("Content-type:application/json;charset=utf-8")
你肯定有include的页面里加这句了
咋去掉的啊 我也出现这种情况了
HTTP/1.1 200 OK
Date: Fri, 18 Apr 2014 09:00:59 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 2352
Cache-Control: private
Content-Type: application/json; charset=utf-8
{"body":{"item":[{"BuyPriceoff":0,"BuyTime":"未确定","CityId":420100,"CityName":"武汉","Content":"白色的年前提车","CountyId":420105,"CountyName":"汉阳","CreateTime":"2014-02-06 11:35:27","DealerId":11569,"HandleTime":"2014-01-07 11:35:28","Id":23010786,"Name":"张国雄","OrderType":0,"Phone":"18108624658","ProvinceId":420000,"ProvinceName":"湖北","ReDealerId":11569,"SeriesId":2945,"SeriesName":"雪铁龙C4L","SpecId":15737,"SpecName":"雪铁龙C4L 2013款 1.8L 手动劲智版","State":1},{"BuyPriceoff":0,"BuyTime":"","CityId":140100,"CityName":"太原","Content":"","CountyId":140105,"CountyName":"小店","CreateTime":"2014-02-06 11:34:35","DealerId":6752,"HandleTime":"2014-01-07 11:34:36","Id":23010726,"Name":"栗","OrderType":1,"Phone":"15386885719","ProvinceId":140000,"ProvinceName":"山西","ReDealerId":6752,"SeriesId":792,"SeriesName":"雪铁龙C5","SpecId":17043,"SpecName":"雪铁龙C5 2013款 2.0L 自动悦享型","State":1},{"BuyPriceoff":0,"BuyTime":"","CityId":440300,"CityName":"深圳","Content":"","CountyId":0,"CountyName":"","CreateTime":"2014-01-07 11:34:30","DealerId":75882,"HandleTime":"","Id":23010715,"Name":"黎","OrderType":0,"Phone":"18320819196","ProvinceId":440000,"ProvinceName":"广东","ReDealerId":0,"SeriesId":2945,"SeriesName":"雪铁龙C4L","SpecId":17658,"SpecName":"雪铁龙C4L 2014款 1.8L 自动智驱版劲智型 ","State":0},{"BuyPriceoff":0,"BuyTime":"","CityId":320300,"CityName":"徐州","Content":"","CountyId":0,"CountyName":"","CreateTime":"2014-01-07 11:34:04","DealerId":5248,"HandleTime":"","Id":23010688,"Name":"吴","OrderType":0,"Phone":"13852043028","ProvinceId":320000,"ProvinceName":"江苏","ReDealerId":0,"SeriesId":2945,"SeriesName":"雪铁龙C4L","SpecId":15739,"SpecName":"雪铁龙C4L 2013款 1.8L 自动劲驰版","State":0},{"BuyPriceoff":0,"BuyTime":"","CityId":440300,"CityName":"深圳","Content":"铂金灰","CountyId":0,"CountyName":"","CreateTime":"2014-02-06 11:33:39","DealerId":9802,"HandleTime":"2014-01-07 11:33:40","Id":23010669,"Name":"潘","OrderType":0,"Phone":"13923846836","ProvinceId":440000,"ProvinceName":"广东","ReDealerId":9802,"SeriesId":2945,"SeriesName":"雪铁龙C4L","SpecId":14551,"SpecName":"雪铁龙C4L 2013款 1.6L 手动劲智版","State":1}],"pages":40337,"total":201683},"cache":1000,"message":"","success":1,"result":0}NULL