我得到了一个andoird应用程序,我想结果返回到我的android textview。我在浏览器上测试它,结果显示,但它没有返回到我的Android应用程序。JSON对象不是从XAMPP服务器返回
以下代码是我的php文件。
<?php
$accounts = mysql_connect("localhost","user123","1234")
or die (mysql_error());
mysql_select_db("user123",$accounts);
if(isset($_GET["id"])){
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM table123 WHERE id = $id");
if($result != null){
$result = mysql_fetch_array($result);
$user = array();
$user["username"] = $result["username"];
$user["password"] = $result["password"];
echo json_encode($user);
}else{
}
}else{
$user["username"] = "not found";
$user["password"] = null;
echo json_encode($user);
}
?>
下面的代码是浏览器的结果
{"username":"not found","password":null}
即使结果没有发现问题,应返回$用户告诉我“找不到”。这是不可能的,任何事情都不会返回流。我已经在我的浏览器上进行了测试,是的,它将$ user返回给我。我的代码有问题吗?
在本地主机上,请尝试将您的PC的IP地址代替。 – Bigflow 2013-02-20 07:48:33
我正在使用android模拟器,我使用ip地址10.0.2.2。我不认为我的IP地址有任何问题,因为我在另一个项目上测试过 – edisonthk 2013-02-20 07:50:27
我仍然会尝试使用本地主机。我知道使用本地主机而不是10.0.2.2出现了错误,并且不会发生任何logcat错误? – Bigflow 2013-02-20 07:52:28