gpt4 book ai didi

php - 使用 PHP 无法获取 JSON 响应?

转载 作者:行者123 更新时间:2023-11-29 11:50:57 25 4
gpt4 key购买 nike

我正在学习创建一个 API 来为我的 Android 应用程序返回 JSON。 http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

如果添加此行,我不会收到 JSON 响应

$product["区域"] = $row["区域"];

如果我从下面的文件中删除上面的行。然后我收到回复。

我什至检查过数据库。我不明白为什么会这样。

提前致谢

这是我的 PHP 文件 (get_all_products)

<?php

/*
* Following code will list all the products
*/

// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// get all products from products table
$result = mysql_query("SELECT * FROM shelter") or die(mysql_error());

// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();

while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["ID"] = $row["ID"];
$product["Timestamp"] = $row["Timestamp"];
$product["Accomodation"] = $row["Accomodation"];
$product["Area"] = $row["Area"];

// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;

// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";

// echo no users JSON
echo json_encode($response);
}
?>

最佳答案

SELECT *FROM Shelter

看起来有点奇怪,不是吗

SELECT * FROM Shelter

还要查看庇护所表中是否有一列“区域”并且其中包含有效数据。

关于php - 使用 PHP 无法获取 JSON 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34076479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com