繁体   English   中英

无法使用PHP获得JSON响应?

[英]Can't get JSON response using PHP?

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

如果添加此行,则无法获取JSON响应

$product["Area"] = $row["Area"];

如果我从下面的文件中删除上述行。 然后我得到了回应。

我什至检查了数据库。 我不知道为什么会这样。

提前致谢

这是我的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

还可以查看庇护所表中是否有“面积”列,其中是否包含有效数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM