Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中将MySQL LONGTEXT输出为JSON_Php_Mysql_Json_Longtext - Fatal编程技术网

在PHP中将MySQL LONGTEXT输出为JSON

在PHP中将MySQL LONGTEXT输出为JSON,php,mysql,json,longtext,Php,Mysql,Json,Longtext,对于一个手机应用程序,我创建了一个API。内容始终是最新的,因为所有内容都来自此API。我现在将其更改为包含更多内容,在我的MySQL数据模型中,我的一个字段是一个LONGTEXT字段,以实现这一点,我希望将其输出到JSON文件中 当输出MySQL表时,JSON文件中会显示所有内容,除了longtext字段,在输出中保持空 <?php include "specialchar.php"; $sqlTour = "SELECT * FROM tour where id = '" . $i

对于一个手机应用程序,我创建了一个API。内容始终是最新的,因为所有内容都来自此API。我现在将其更改为包含更多内容,在我的MySQL数据模型中,我的一个字段是一个LONGTEXT字段,以实现这一点,我希望将其输出到JSON文件中

当输出MySQL表时,JSON文件中会显示所有内容,除了longtext字段,在输出中保持空

<?php

include "specialchar.php";

$sqlTour = "SELECT * FROM tour where id = '" . $id . "'";
$sqlSteps = "SELECT * FROM tourSteps where id = '" . $id . "'";
$resultTour = mysqli_query($con, $sqlTour);
$resultSteps = mysqli_query($con, $sqlSteps);

$json = array();
$json2 = array();

$json = (mysqli_fetch_array($resultTour));

$json = array_map("utf8_encode", $json);

while ($row = mysqli_fetch_array($resultSteps)) {
  //create JSON output;
  $json2[] = array_map("utf8_encode", $row);
}

$json['steps'] = $json2;
$response['audiotour'] = $json;

$response = json_encode($response);
echo(Utf8_ansi($response));

$con->close();

?>

有人有主意吗


我尝试在JSON编码函数中使用JSON_HEX_标记、JSON_HEX_AMP、JSON_HEX_APOS、JSON_HEX_QUOT

我的变量名不匹配。问题现在解决了,无需更改此代码。

存储在longtext上的示例数据?
$data=json_encode($array,json_HEX QUOT)应该可以正常工作。您可以使用json_last_error查看列的错误,可能您的文本包含格式错误的字符。