在一種 PHP 中,android 嘗試發(fā)送不止一種 json 格式,但只收到一種。我應(yīng)該怎么辦?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'而不是輸出。我認(rèn)為我們沒有從“getJSONArray(“收藏夾”)”中獲取值。我應(yīng)該怎么辦?//--------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;
在一種 PHP 中,android 嘗試發(fā)送不止一種 json 格式,但只收到一種。我應(yīng)該怎么辦?
慕標(biāo)琳琳
2023-07-13 13:55:43