我正在使用 xampp,即使我在我的表中将 id 列设置为整数,输出仍然是字符串,即我得到"id":"1"而不是"id":1. 我遇到了一个可能的解决方案,JSON_NUMERIC_CHECK但我不知道如何在我的 php 脚本中实现它。有人可以告诉我如何修改我的 php 脚本,以便将 id 输出作为整数。
<?php
require("config.inc.php");
$query_params=null;
$query = "Select * FROM feeds";
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
$rows = $stmt->fetchAll();
if ($rows) {
$response["feed"] = array();
foreach ($rows as $row) {
$post = array();
$post["id"] = $row["id"];
$post["name"] = $row["name"];
$post["image"] = $row["image"];
array_push($response["feed"], $post);
}
echo json_encode($response);
} …Run Code Online (Sandbox Code Playgroud)