Home > Backend Development > PHP Tutorial > PHP在安卓接口开发中遇到乱码的问题,希望大神可以解答一下

PHP在安卓接口开发中遇到乱码的问题,希望大神可以解答一下

WBOY
Release: 2016-06-23 13:30:45
Original
869 people have browsed it


发送给安卓的接口中的json数据莫名其妙的多了个头,请问有没有大神也遇到过这样的情况,怎么解决的?


回复讨论(解决方案)

不好判断,不是BOM吧,发代码看下

显然是 BOM 头,而且有 4 个

之前我也遇到了,验证json的时候显示不通过,查看了很多文件,才发现是我的配置文件变成了UTF-8 +BOM

自己写的时候 就得一条一条测试过去 放json格式化工具之类的验证一下是否正确

$api=$_GET['api'];
require("config/sql_configs.php");
require("config/function.php");
if($api=="login"){ 
$user=$_GET['user'];
$pwd=$_GET['pwd'];
$arr=login( $user );
if ($arr ['error_zt']=="0"){
if ($pwd==$arr['pwd']){
login_log($user);
$zt = "0";
$arr_1['id']=$arr['id'];
$arr_1['user']=$arr['user'];
$arr_1['zt']=$zt;
$arr_1['type']=$arr['type'];
}else{
$zt = "1";
$arr_1['zt']=$zt;
}
echo json_encode($arr_1);
   }else{
echo json_encode($error);
   }
}
?>
这是代码

谢谢你们,真是BOM头,非常感谢

config/sql_configs.php 和 config/function.php 中还有 require 语句吗?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template