我在哪里收到我从android发送的对象?

时间:2013-12-14 12:21:03

标签: php android json

我有这个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发送的那些回复?

1 个答案:

答案 0 :(得分:0)

从你正在获得响应的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);