【问题标题】:Replacement of json url with php url not working用php url替换json url不起作用
【发布时间】:2016-05-02 05:45:34
【问题描述】:

我正在开发一个带有一些文本的列表视图从服务器检索的 android 应用程序源在这里source link。这是我的php代码

<?php
require_once("dbConnect.php");
$sql = "SELECT image,fullname,location from uploadfinding";
$res = mysqli_query($conn,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
        array_push($result, array(
            "image"=>$row[0],
            "fullname"=>$row[1],
            "location"=>$row[2]));
           echo " over";
            }
        echo json_encode($result);
      mysqli_close($conn);
?>

这是我的 json 响应

 Connected successfully over over over[{"image":myurl\/uploadfinding\/uploads\/2016-04-25 06:38:051461584281226.jpg","fullname":"adi","location":"fgh"},{"image":myurl\/uploadfinding\/uploads\/2016-04-25 06:38:201461584297706.jpg","fullname":"adi2","location":"fgh2"},{"image":myurl\/uploadfinding\/uploads\/2016-04-25 06:45:441461584739479.jpg","fullname":"adi23","location":"cn"}]

我尝试了很多东西,但没有结果。完整的源代码在这里:

我没有在这里发布任何 java 文件,因为这个例子适用于这个 url:

http://api.androidhive.info/json/movies.json

但是当我用我的网址替换它时:

http://myurl/PhotoUpload/getAllImages.php

它只返回空活动。

【问题讨论】:

  • 用你放置 php 文件的服务器 URL 更改 'myurl'。
  • 亲爱的我的网址没关系...
  • 您好,您是否检查过数据是否进入数组$result
  • 我没明白你的意思..

标签: php android json listview android-volley


【解决方案1】:

试试这个

<?php
    header("content-type:application/json");
    require_once("dbConnect.php");

    $sql = "SELECT x1,x2,x3 from table_name";

    $res = mysqli_query($conn,$sql);


    $result = array();

    while($row = mysqli_fetch_array($res)){
            array_push($result, array(

                "x1"=>$row["x1"],
                "x2"=>$row['x2'],
                "x3"=>$row["x3"]));

                echo " over";
            }


    echo json_encode($result);
    $fp = fopen('results.json', 'w');
fwrite($fp, json_encode($result));
fclose($fp);

    mysqli_close($conn);

    ?>

将您的网址“http://myurl/PhotoUpload/getAllImages.php”替换为“http://myurl/PhotoUpload/results.json

【讨论】:

    【解决方案2】:

    只是为了澄清: 在您的应用程序中,您可以简单地将模拟器称为

    “本地主机”或 127.0.0.1。

    如果您使用真实设备运行,则意味着传递正确的 url,例如

    http://xxx.xxx.xxx.xxx/android/php_server/register.php

    编辑:

    尝试比较你的网址,

    myurl/uploadfinding/uploads/2016-04-25 06:38:051461584281226.jpg"

    http://api.androidhive.info/json/movies/1.jpg”这个。

    在您的回复中,"图片标签前面缺少双引号

    传递图片链接,

    “你的链接”

    【讨论】:

    • 我认为响应不好。检查我的更新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多