2017-03-01 113 views
0

我有一個數據編碼問題。我的數據庫在其中一列中有口音,在api中返回一個PDO查詢SQL SERVER中的列。只要我返回,我通過json_encode方法轉換成JSON,再加上JSON就是NULL。當我給var_dump帶有重音符號的問號時,這個字符會出現' ',而json是空的。 我知道這是我需要轉換爲UTF8的編碼,但我無法在php中進行此轉換。誰能幫我?返回JSON NULL

enter image description here

+0

幫助嗎? http://stackoverflow.com/questions/16800915/php-pdo-charset-utf8-an-invalid-keyword-charset-was-specified-in-the-dsn-str –

+0

嘗試'utf_encode()'並檢查。你能否也請告訴那裏的原始人物是什麼? –

+0

<?php ini_set('display_errors',1); ini_set('display_startup_errors',1); include_once'../../../config.php'; include_once'../../../config.php'; include_once'../api/helpdesk.php'; include_once'../api/conexaoSql.php'; require_login(); $ codigo = $ _GET ['id']; 嘗試{ $ objHelp = new helpdesk(); $ mensagens = $ objHelp-> SelecionaMensagem($ codigo); // var_dump($ mensagens); echo json_encode($ mensagens,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ($ e-> getMessage());}};}};}}; } –

回答

-2

你指定的字符集權的頭?

header('Content-type: text/html; charset=utf-8');

還請注意,您的列和表應該是utf8_unicode_ci

最後你的連接到數據庫也應該相應地設置charset=utf8

+0

在發佈我的答案後不到1秒鐘,就低估了我:非常感謝。 – Ditto

+0

不客氣。這個問題與Content-type:text/html無關。與MySQL無關。 –

+0

@YourCommonSense你在不到1秒的時間內看到了這一切。涼。 – Ditto