用php url替换json url不起作用

时间:2016-05-02 05:45:34

标签: php android json listview android-volley

我正在使用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文件,因为这个例子适用于这个网址:

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

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

http://myurl/PhotoUpload/getAllImages.php

它只返回空活动。

2 个答案:

答案 0 :(得分:0)

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

  

&#39;本地主机&#39;或127.0.0.1。

如果您使用真实设备运行,请传递正确的网址,如

  

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

编辑:

尝试比较您的网址,

  

myurl / uploadfinding / uploads / 2016-04-25 06:38:051461584281226.jpg&#34;

  

&#34; http://api.androidhive.info/json/movies/1.jpg&#34;此

根据您的回复,图片代码前面缺少&#34; 双引号

传递图片链接,

  

&#34; your_link&#34;

答案 1 :(得分:0)

试试这个

<?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);

    ?>

替换您的网址&#34; http://myurl/PhotoUpload/getAllImages.php&#34;使用&#34; http://myurl/PhotoUpload/results.json&#34;