簡體   English   中英

在哪里可以收到從android中的php發送的對象?

[英]where do i receive the objects i sent from php in android?

我有這個php代碼,我不知道如何將代碼末尾發送的所有那些數組放到一個數組中,這樣我就可以將此數組發送給android了?

$username = $_POST["username"];  
$locations_string = "";
$names = array();
$response1= array();
$response2= array();
$user_record = mysql_query("SELECT * FROM users WHERE username='$username'");
$value = mysql_fetch_array($user_record);
$userlocation = $value['location'];

$query = mysql_query("SELECT * FROM AllFriendsExceptBlocked WHERE username ='$username'       ");

while($row = mysql_fetch_array($query) ){
array_push($names , $value["friendname"]);

echo $row['friendname']. " - ". $row['location'];
echo "<br />";
}
for($i=0; $i < count($names) ; $i++){
$friend = $names[$i];
$user_record = mysql_query("SELECT * FROM AllFriendsExceptBlocked WHERE     friendname='$friend' ");
$value = mysql_fetch_array($user_record);
$locations_string = $locations_string . "," . $value['location'];

}
$response["message"] = "send locations of friends in AllFriendsExceptBlocked";
$response1["panicedUserLocation"] = $userlocation;
$response2["locations"] = $locations_string;

echo json_encode($response);
json_encode($response);
echo json_encode($response2);
json_encode($response2);
echo json_encode($response2);
json_encode($response2);

現在我該如何接收我從android中的php發送的響應?

從獲取響應的http調用中,嘗試將響應轉換為json對象。 例。

InputStream JsonStream=responce.getEntity().getContent();
BufferedReader reader= new BufferedReader(new InputStreamReader(JsonStream));
StringBuilder builder = new StringBuilder();
String line;
while((line=reader.readLine())!=null)
{

    builder.append(line);
}
String JSONdata = builder.toString();
Log.i("JsonData",JSONdata);
JSONObject json = new JSONObject(JSONdata);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM