0

这是我的 PHP 脚本:

<?php

header('Content-Type: application/json; charset=utf-8');
$link = mysql_pconnect("localhost", "test", "test") or die("Could not connect");
mysql_select_db("myradio") or die("Could not select database");

$arr = array();

$rs = mysql_query("SELECT * FROM radio1");

while($obj = mysql_fetch_assoc($rs)) {
    $arr[] = $obj;
}
echo '{"success":true,"error":"","data":{"schedule":['.json_encode ($arr).']}}';
    ?>

JSON 显示良好,但是斜杠没有转义,这会导致:

这是周末

什么时候应该:这是周末

在 JSON 中。

另外,我如何操作我的 PHP/JSON,以便根据回调,它会给出以下错误消息:

({"success":false,"error":"File does not exist"});

到目前为止它运行良好,只需要获得更精细的细节,将不胜感激!

至于我的 PHP,我在 MAMP 服务器上使用 PHP 5.4.10,如果有任何相关性的话。

4

1 回答 1

-1

仔细阅读这篇文章。它描述了如何通过在 json_encode 函数中使用不同的选项(如 JSON_UNESCAPED_UNICODE)对特殊符号(如 '\' )进行编码来转义它们。

于 2013-07-12T11:05:45.470 回答