dsm42026 2015-03-02 18:17
浏览 122

PHP PDO - 使用UTF-8编码的Json

I have this data to datatable cell: AlgoVital Plus čćš so some characters is utf-8

Here's my database schema

enter image description here

After that I make json file with php and send it to fronted:

//header
header('Content-Type: text/html; charset=utf-8');
...
...
//at the end of php file:
 $jsonTable = json_encode($table);
    //echo $jsonTable;
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    echo $jsonTable;

and HTML head is OK too:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">

but I cant show data with utf-8 characters... WHy?

JSON is not format with utf-8 characers... etc. where I have some characters like čćšž then I just get NULL at JSON file, when I use json encode

How I can solve this?

  • 写回答

2条回答 默认 最新

  • dongzhi9906 2015-03-02 18:33
    关注

    Try with this:

    $table = utf8_encode($table);
    $jsonTable = json_encode($table);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题