json_encode utf-8问题

Vel*_*tar 4 php json

我从数据库中检索mysqli-resultset,来自utf-8编码表,然后插入到数组中:

$json = array();

$query = "select artikel_titel from tblArtikel";
if($result = mysqli_query($link, $query))
{
    while($line = mysqli_fetch_array($result, MYSQLI_NUM)) {
    array_push($json, $line);
}
echo json_encode($json);
Run Code Online (Sandbox Code Playgroud)

数组是正确构建的,你可以在这里看到它在 页面的底部你可以看到json_encode创建的错误.我怎样才能解决这个问题?

Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13 Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13 Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13
Run Code Online (Sandbox Code Playgroud)

lan*_*nzz 9

您的数据中确实存在无效的UTF-8序列; 显然你的数据库结果是ISO-8859-1.json_encode工作使用UTF-8的数据,根据该文档.您必须确保您的数据是UTF-8,并且您的数据库连接也使用UTF-8; 或者,您可以使用iconv()将结果转换为UTF-8,然后再将其转换为UTF-8 json_encode.

  • 您的转储在几个字符串中显示[Unicode替换字符](http://en.wikipedia.org/wiki/Replacement_character),在我将浏览器的编码强制转换为ISO-8859-1后,这些字符串显示正确. (2认同)