我正在使用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);
} else {
$response["success"] = 0;
$response["message"] = "No Post Available!";
die(json_encode($response));
}
?>
json_encode($response, JSON_NUMERIC_CHECK);
。 - AbraCadaver