【问题标题】:Return php query to json null why?将 php 查询返回到 json null 为什么?
【发布时间】:2016-07-25 09:55:40
【问题描述】:

有人可以帮我吗,我该怎么办?请帮忙。

$resultG = mysqli_query($db,"select * from Rubrica where ID_Dispositivo = '$UserID' ");
                                    $response = array();
                                    while($row = mysqli_fetch_assoc($resultG)){
                                        $response[] = $row;
                                    }
echo json_encode($response);

响应是 D/doInBackground(Resp): []

为什么是空???

【问题讨论】:

  • 你是否尝试打印_r($row);
  • 直接在数据库上尝试查询。除了您之外,没有人可以知道是否有与您的查询匹配的数据...
  • 为什么行?,我需要编码为 json
  • 它提供数据但不返回

标签: java php android arrays json


【解决方案1】:

mysqli_fetch_assoc 返回对应于获取行的字符串关联数组。尝试改变

$resultG = mysqli_query($db,"select * from Rubrica where ID_Dispositivo = '$UserID' ");
while($row = mysqli_fetch_assoc($resultG)){
echo json_encode($row);
}

【讨论】:

  • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您正在为将来的读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性的 cmets 挤满你的代码,因为这会降低代码和解释的可读性!
猜你喜欢
  • 2020-03-01
相关资源
最近更新 更多