[英]PHP JSON Special Characters
我手上應該有返回一些json類型的結果。 但由於特殊字符,我無法輸出。 內容數組中的示例數據:
Alt�n Portakal Film Festivali sonu�land�。
(問題: �
)
$JSON["today"]=array();
for ($i=0; $i < count($olay_tarih); $i++) {
$gelen["date"] = array();
$gelen["content"]=array();
array_push($gelen["date"], $olay_date[$i]);
array_push($gelen["content"], $olay_content[$i]);
array_push($JSON["today"], $gelen);
}
echo json_encode($JSON);
將您的代碼更改為:
header('Content-Type: application/json; charset=utf-8', true,200);
$JSON["today"]=array();
for ($i=0; $i < count($olay_tarih); $i++) {
$gelen["date"]=array();
$gelen["content"]=array();
array_push($gelen["date"], $olay_date[$i]);
array_push($gelen["content"], $olay_content[$i]);
array_push($JSON["today"], $gelen);
}
$JSON = array_map('utf8_encode', $JSON);
echo json_encode($JSON);
添加 UTF-8 標頭將使瀏覽器識別此設置的任何特殊字符。
這個的輸出是什么?
<?php
header('Content-Type: text/html');
echo(json_encode($JSON, JSON_UNESCAPED_UNICODE));
JSON_UNESCAPED_UNICODE
按字面編碼多字節 Unicode 字符(默認為轉義為\uXXXX
)。 自 PHP 5.4.0 起可用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.