2013-12-14 2 views
0

나는이 PHP 코드를 가지고 있으며, 어떻게이 배열을 안드로이드에 보낼 수 있도록 코드의 끝에 하나의 배열로 보낼 수 있는지 모르겠습니다.안드로이드에서 PHP로 보낸 객체를 어디에서받을 수 있습니까?

$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); 

이제 어떻게 답변을받을 수 있습니까?

답변

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); 
+0

오케이 내가 잘못하고있다. 나는 하나의 배열만을 보내야한다. 나는 모든 배열을 보낼 수 없다! 그래서이 모든 응답을 묶는 방법에 대한 아이디어는? – user3101219

+0

당신은 하나의 배열에 중첩 배열을 가질 수 있습니다 : {{}, {}} –

관련 문제