>  기사  >  php教程  >  看不见的问题(个性的json)

看不见的问题(个性的json)

PHP中文网
PHP中文网원래의
2016-05-25 16:58:261130검색

在服务端返回json数据时,文件保存成utf8,json解析不了。而把文件保存成utf8无BOM就可以解析。
就因为几个用肉眼看不到的字符  

case sentence_info:  // 每日一句列表
         
        $pageIndex=($_POST[pageIndex]-1)*$_POST[displayNumber];
        $displayNumber=$_POST[displayNumber];
        // $month=$_POST[month];
        $result_num = mysql_query("select sid from i_sentence");
        $total = mysql_num_rows($result_num);
        $total_page=ceil($total/$displayNumber);
        $arr=array();
        $query=mysql_query("select sid,picture,picture2,content,note,browsenum,translation,tts,
        dateline from i_sentence where 1=1 order by dateline desc limit $pageIndex,$displayNumber");
 
        while($row=mysql_fetch_assoc($query))
        {
             
            $row[note]=urlencode(preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$row[note]));
            $row[translation]=urlencode(preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$row[translation]));   
            // $row[imgs]=get_img($row[id]);
            $row[dateline]=urlencode(date('Y M d',strtotime($row[dateline])));
            $picinto=pathinfo($row[picture2]);  
            if(!empty($picinto[extension]))
            {
                $row[picture]=$row[picture2];
            }
            unset($row[picture2]); 
            $arr[]=$row;
        }
        $data=urldecode(json_encode($arr));
        $s=mysql_errno();
        //echo $data;
        echo "{\"s\":$s,\"data\":$data,\"total\":$total_page}";
         
    break;

 以上就是看不见的问题(个性的json)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

                   

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.