我得到了一個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