在一种 PHP 中,android 尝试发送不止一种 json 格式,但只收到一种。我应该怎么办?
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Log.d("GGGG","onResponse start");
JSONObject jsonResponse = new JSONObject(response);
Log.d("GGGG","test" );
JSONArray jsonArray = jsonResponse.getJSONArray("Search");
Log.d("GGGG","test1" );
JSONArray jsonArray2 = jsonResponse.getJSONArray("Favorite");
Log.d("GGGG","test2" );
日志到Logcat.d是输出到'test1'而不是输出。我认为我们没有从“getJSONArray(“收藏夹”)”中获取值。我应该怎么办?
//--------PHP--------//
$userID =$_POST["userId"];
$keyWord = $_POST["keyWord"];
// $keyWord = "na";
// $userID ="test";
//데이터베이스에 값을 넣는부분
$statement ="SELECT * from music where music_title like '%$keyWord%' or music_singer like '%$keyWord%'";
// echo $statement;
// exit;
$result = mysqli_query($con,$statement);
$resultArray = array();
while($rows=mysqli_fetch_assoc($result)){
$resultArray[]=$rows;
}
$statement ="SELECT * from favorite_playlist WHERE user_id ='$userID'";
$result = mysqli_query($con,$statement);
$resultArray2 = array();
while($rows=mysqli_fetch_assoc($result)){
$resultArray2[]=$rows;
}
//$response["success"] = true;//success라는 인덱스에 true값을 넣어줌
header('Content-Type: application/json; charset=utf8');
$json = json_encode(array("Search"=>$resultArray), JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
$json2 = json_encode(array("Favorite"=>$resultArray2), JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
//echo json_encode($resultArray);//JSON형식으로 출력
echo $json;
echo $json2;
梵蒂冈之花
相关分类