我正在使用 CakePHP 输出一个包含多个 UTF-8 编码字符串的数组。我为输出设置了布局(这是一种 REST API 方法):
<?php.
header("Pragma: no-cache");.
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");.
header('Content-Type: application/json; charset=UTF-8');.
header("X-JSON: ".$content_for_layout);.
echo $content_for_layout;.
?>
这是我的看法:
<?php echo json_encode($items); ?>
我获取数据的数据库表以 utf-8 编码。但是,当我输出数据时,如果其中一个元素具有 à、á 等特殊字符,则该字符串将在 JSON 数组中设置为 null。如何正确输出我的数据?