php - JSON 输出为空
问题描述
我有以下 PHP 代码来返回一些 JSON 编码的结果。如果我双重编码(即在我将当前行添加到数组的位置放置一个 json_encode),我会得到一个过度处理(到处都有很多“/”)但完整的输出。因为它在这里,我什么也得不到。
$link = mysqli_connect("localhost","steph_stephen", "haltermann1!", "stephenh_tanks");
if (!$link){
die("Conection failed: " . mysqli_connect_error());
}
$query="SELECT * FROM Tank";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) > 0){
$myArray = array();
header('Content-type:application/json');
while($tank = mysqli_fetch_assoc($result))
{
//$myArray[] = json_encode($tank); if i leave this line in (and comment the line below) - i get the full but over-process json result
$myArray[] = $tank; //without the line above no json string is returned
}
print json_encode($myArray);
}
else
{
echo "Could not execute query";
echo mysqli_error($link);
}
mysqli_close($link);
下面是返回的 JSON 的一小部分(尽管处理过度)
["{\"tank\":\"001\",\"product\":\"Caromax 20HN B\\\/F\",\"prod_code\":\"51533\",\"tank_level\":\"7888\",\"volume\":\"1325818\",\"pump_volume\":\"1275282\",\"max_volume\":\"1759741\",\"tank_status\":\"For Test\"}"...
解决方案
推荐阅读
- python - 保护 python 应用程序
- rest - How to take values of Jmeter variable in coma separated way
- svn - svn冲突问题
- typescript - 使用给定 Vue 构造函数的插件与 vue-component-class 进行组件继承
- c# - 使用嵌入式图像 gmail api 创建电子邮件
- javascript - Cytoscape.js 在循环中创建时,所有节点都在彼此之上
- web - 仅将 Google 跟踪代码管理器过滤到我的主域(排除测试环境)?
- google-chrome - Chrome WebExtension - 私人商店和企业环境
- javascript - vscode - 用 node_modules 定义替换打字稿定义
- python - 如何合并小面积的矩形(OpenCV,Python)