简体   繁体   English

在哪里可以收到从android中的php发送的对象?

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

I have this php code and i don't know how can i put all those arrays i send at the end of the code into only one array so that i can send this array to 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);

now how can i receive those responses i sent from the php in android? 现在我该如何接收我从android中的php发送的响应?

from the http call where you are getting response try to convert the response to json object. 从获取响应的http调用中,尝试将响应转换为json对象。 example. 例。

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