php json_encode中提示的中文總是返回"\u767b\u5f55\u6210\u529f\uff01"的解決辦法

來源:互聯網
上載者:User

標籤:提示   esc   技術   失敗   etc   http   9.png   pre   輸出   

最近在練習使用 php 寫一些簡單的介面,但是在返回的訊息中,如果有中文,在測試後總是返回:

{"resultCode":200,"message":"\u767b\u5f55\u6210\u529f\uff01","data":{"user_id":"29","user_phone":"13918145846","user_name":null,"user_sex":null,"user_password":"123456","user_header":null}}

下面是我寫的:

$row = mysql_num_rows($result);    if($row == 1){        $array = array();        while($row = mysql_fetch_array($result)){            $array["user_id"] = $row["user_id"];            $array["user_phone"] = $row["user_phone"];            $array["user_name"] = $row["user_name"];            $array["user_sex"] = $row["user_sex"];            $array["user_password"] = $row["user_password"];            $array["user_header"] = $row["user_header"];        }        //把上面的數組以 json 格式返回        $json = json_encode(array(            "resultCode"=>200,            "message"=>"登入成功!",            "data"=>$array        ));        echo($json);    }else{        $json = json_encode(array(            "resultCode"=>500,            "message"=>"登入失敗!"        ));        echo($json);    }

之前在測試時,一直顯示這個個?

通過網上查資料並交通,得知 php5.4 Json新增了一個選項: JSON_UNESCAPED_UNICODE, 故名思議, 就是說, Json不要編碼Unicode.

我們只要在 json_encode(array(),JSON_UNESCAPED_UNICODE),就可以將代碼中的中文正常輸出:

$json = json_encode(array(            "resultCode"=>200,            "message"=>"登入成功!",            "data"=>$array        ),JSON_UNESCAPED_UNICODE);        echo($json);

看測試效果:

就是這幾個單詞不好拼!!!!

php json_encode中提示的中文總是返回"\u767b\u5f55\u6210\u529f\uff01"的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.